0


【Rust 日报】2023-1-20 西门子在一次内部Rust Meetup上介绍了Rust在列车控制网络中的应用...

推上说西门子在一次内部Rust Meetup上介绍了Rust在列车控制网络中的应用

Daniel Bovensiepen Li
@bovensiepen
Today's Rust Meetup at Siemens introduced the application of Rust in train control networks. Things are moving 🥰

https://twitter.com/bovensiepen/status/1616367973475966976

Coerce-rs Actor模型分布式应用框架

使用它你可以方便地实现基于Actor模型的分布式系统。

https://github.com/LeonHartley/Coerce-rs

justjson - 又一个rust json parser

已有的框架不满足作者的需求,一怒之下自己造了一个。所说性能还很好(当然评测是有技巧的)。

https://ecton.dev/rust-json-ecosystem/

Rust操作符重载可以玩出什么花样?

下面是6个例子:

  1. ## C++ Input/Output
  2. Instead of
  3. stdin().read_line(&mut buffer).unwrap();
  4. println!("Hello I am {name}!!!");
  5. we can overload the shift operators on cin and cout to allow
  6. cin >> &mut buffer;
  7. cout << "Hello I am " << name << "!!!" << endl;
  8. ## Variadic Functions
  9. Instead of
  10. std::cmp::max(x, y);
  11. [w, x, y, z].into_iter().max();
  12. we can make
  13. // max+ is like std::cmp::max but better
  14. // it supports >2 arguments
  15. max+(x, y);
  16. max+(w, x, y, z);
  17. ## More Concise Builders
  18. Here's a more serious one. Builder pattern sometimes involve a lot of repeated method calls. Take for example this usage of the warp web framework.
  19. let hi = warp::path("hello")
  20. .and(warp::path::param())
  21. .and(warp::header("user-agent"))
  22. .map(|param: String, agent: String| {
  23. format!("Hello {}, whose agent is {}", param, agent)
  24. });
  25. What if the API look like this instead?
  26. let hi = warp::path("hello")
  27. + warp::path::param()
  28. + warp::header("user-agent")
  29. >> |param: String, agent: String| {
  30. format!("Hello {}, whose agent is {}", param, agent)
  31. };
  32. ## Infix Functions
  33. Instead of
  34. x.pow(y);
  35. dot_product(a, b);
  36. a.cross(b.cross(c).cross(d))
  37. we can make
  38. x ^pow^ y;
  39. a *dot* b;
  40. a *cross* (b *cross* c *cross* d);
  41. Lots of people wanted this!
  42. ## Doublefish
  43. std::mem provides these functions
  44. size_of::<T>();
  45. size_of_val(&value);
  46. Turbofish enthusiasts would enjoy size_of but not so much size_of_val, so let's make our own improved version of size_of_val that's more turbofishy
  47. size_of::<T>();
  48. size_of_val<<&value>>();
  49. ## Join and Race
  50. Futures combinators can have short-circuiting behaviors
  51. // quit if any of the 3 errors
  52. (fut1, fut2, fut3).try_join().await;
  53. // quit if any of the 3 succeeds
  54. (fut4, fut5, fut6).race_ok().await;
  55. let's communicate this through & and |
  56. (TryJoin >> fut1 & fut2 & fut3).await;
  57. (RaceOk >> fut4 | fut5 | fut6).await;

https://wishawa.github.io/posts/fun-rust-operators/

--
From 日报小组 Mike

社区学习交流平台订阅:

  • Rust.cc 论坛: 支持 rss
  • 微信公众号:Rust 语言中文社区

本文转载自: https://blog.csdn.net/u012067469/article/details/128747859
版权归原作者 Rust语言中文社区 所有, 如有侵权,请联系我们删除。

“【Rust 日报】2023-1-20 西门子在一次内部Rust Meetup上介绍了Rust在列车控制网络中的应用...”的评论:

还没有评论