< 返回版块

Mike Tang 发表于 2023-01-21 23:00

推上说西门子在一次内部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个例子:

## C++ Input/Output

Instead of

stdin().read_line(&mut buffer).unwrap();
println!("Hello I am {name}!!!");

we can overload the shift operators on cin and cout to allow

cin >> &mut buffer;
cout << "Hello I am " << name << "!!!" << endl;

## Variadic Functions

Instead of

std::cmp::max(x, y);
[w, x, y, z].into_iter().max();

we can make

// max+ is like std::cmp::max but better
// it supports >2 arguments
max+(x, y);
max+(w, x, y, z);

## More Concise Builders

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.

let hi = warp::path("hello")
    .and(warp::path::param())
    .and(warp::header("user-agent"))
    .map(|param: String, agent: String| {
        format!("Hello {}, whose agent is {}", param, agent)
    });

What if the API look like this instead?

let hi = warp::path("hello")
	+	warp::path::param()
	+	warp::header("user-agent")
	>>	|param: String, agent: String| {
			format!("Hello {}, whose agent is {}", param, agent)
		};

## Infix Functions

Instead of

x.pow(y);
dot_product(a, b);
a.cross(b.cross(c).cross(d))

we can make

x ^pow^ y;
a *dot* b;
a *cross* (b *cross* c *cross* d);

Lots of people wanted this!

## Doublefish

std::mem provides these functions

size_of::<T>();
size_of_val(&value);

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

size_of::<T>();
size_of_val<<&value>>();

## Join and Race

Futures combinators can have short-circuiting behaviors

// quit if any of the 3 errors
(fut1, fut2, fut3).try_join().await;

// quit if any of the 3 succeeds
(fut4, fut5, fut6).race_ok().await;

let's communicate this through & and |

(TryJoin >> fut1 & fut2 & fut3).await;
(RaceOk >> fut4 | fut5 | fut6).await;


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

--
From 日报小组 Mike

社区学习交流平台订阅:

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

评论区

写评论

还没有评论

1 共 0 条评论, 1 页