Crates.io | xtra |
lib.rs | xtra |
version | 0.6.0 |
source | src |
created_at | 2020-01-20 18:14:15.318436 |
updated_at | 2024-02-02 07:26:53.35757 |
description | A tiny actor framework |
homepage | |
repository | https://github.com/Restioson/xtra |
max_upload_size | |
id | 200515 |
size | 218,660 |
A tiny, fast, and safe actor framework. It is modelled around Actix (copyright and license here).
futures
).Handler
interface which allows async
/await
syntax with &mut self
.spawn
functions are provided
for Tokio, async-std, smol, and
wasm-bindgen-futures.use xtra::prelude::*;
#[derive(Default, xtra::Actor)]
struct Printer {
times: usize,
}
struct Print(String);
impl Handler<Print> for Printer {
type Return = ();
async fn handle(&mut self, print: Print, _ctx: &mut Context<Self>) {
self.times += 1;
println!("Printing {}. Printed {} times so far.", print.0, self.times);
}
}
#[tokio::main]
async fn main() {
let addr = xtra::spawn_tokio(Printer::default(), None);
loop {
addr.send(Print("hello".to_string()))
.await
.expect("Printer should not be dropped");
}
}
For a longer example, check out Vertex, a chat application written with xtra and spaad on the server.
Check out the docs and the examples to get started!
Enabling the tokio
, async_std
, smol
, or wasm_bindgen
features is recommended in order to enable some convenience methods (such as xtra::spawn_tokio
).
Which you enable will depend on which executor you want to use (check out their docs to learn more about each).
If you have any questions, feel free to open an issue or message me on the Rust discord.
Keep in mind that xtra
has a MSRV of 1.60.0.
async_std
: enables integration with async-std.smol
: enables integration with smol.
Note that this requires smol 1.1 as 1.1 had a minor breaking change from 1.0 which leads to xtra no longer compiling on 1.0 and 1.1 simultaneously.tokio
: enables integration with tokio.wasm_bindgen
: enables integration with wasm-bindgen, and particularly its futures crate.instrumentation
: Adds a dependency on tracing
and creates spans for message sending and handling on actors.sink
: Adds Address::into_sink
and MessageChannel::into_sink
.macros
: Enables the Actor
custom derive macro.To see the breaking changes for each version, see here. The latest version is 0.6.0.