12 个版本 (7 个重大更新)
新 0.10.0 | 2024年8月13日 |
---|---|
0.9.0 | 2024年5月31日 |
0.8.3 | 2023年2月28日 |
0.8.2 | 2022年9月7日 |
0.4.1 | 2021年3月4日 |
#115 in 并发
在 downtown 中使用
70KB
1K SLoC
tonari-actor
这个crate旨在为Rust提供一个简洁且高性能的演员框架,其复杂性显著低于像Actix这样的其他框架。
在这个框架中,每个Actor
都是它自己的操作系统级别的线程。这使得调试变得明显简单,并且在演员数量少于或等于CPU线程数量时性能合适。
示例
use tonari_actor::{Actor, Context, System};
struct TestActor {}
impl Actor for TestActor {
type Error = ();
type Message = usize;
fn name() -> &'static str {
"TestActor"
}
fn handle(&mut self, _context: &Context<Self>, message: Self::Message) -> Result<(), ()> {
println!("message: {}", message);
Ok(())
}
}
fn main() {
let mut system = System::new("default");
// will spin up a new thread running this actor
let addr = system.spawn(TestActor {}).unwrap();
// send messages to actors to spin off work...
addr.send(1usize).unwrap();
// ask the actors to finish and join the threads.
system.shutdown().unwrap();
}
依赖项
- cargo
- rustc
构建
$ cargo build --release
测试
$ cargo test
代码格式
当前格式化选项使用仅nightly版本支持的功能。
$ cargo +nightly fmt
代码检查
$ cargo clippy
依赖项
~1.4–7MB
~30K SLoC