xtra
A tiny, fast, and safe actor framework. It is modelled around Actix (copyright and license here).
For better ergonomics with xtra, try the spaad crate.
Features
- Safe: there is no unsafe code in xtra.
- Tiny: xtra is only ~1.1kloc.
- Lightweight: it only depends on
futuresandasync_traitby default. - Asynchronous and synchronous message handlers.
- Simple asynchronous message handling interface which allows
async/awaitsyntax even when borrowingself. - Does not depend on its own runtime and can be run with any futures executor (Tokio,
async-std, smol, and
wasm-bindgen-futures have the
Actor::spawnconvenience method implemented out of the box). - Quite fast. Running on Tokio, <170ns time from sending a message to it being processed for sending without waiting for a result on my development machine with an AMD Ryzen 3 3200G.
- However, it is also relatively new and less mature than other options.
Example
use *;
use async_trait;
;
// In the real world, the synchronous SyncHandler trait would be better-suited
async
For a longer example, check out Vertex, a chat application written with xtra and spaad on the server.
Too verbose? Check out the spaad sister-crate!
Okay, sounds great! How do I use it?
Check out the docs and the examples
to get started! Enabling the with-tokio-0_2, with-async_std-1, with-smol-0_3, or with-wasm-bindgen-0_2 features
is recommended in order to enable some convenience methods (such as Actor::spawn). 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.
Latest Breaking Changes
- The
SyncHandlertrait has been removed. This simplifies the API and should not change the performance on stable.- How to upgrade: change all implementations of the
SyncHandlertrait to the normalHandlertrait.
- How to upgrade: change all implementations of the
- All
Actorlifecycle messages are now async. This allows to do more kinds of things in lifecycle methods, while adding no restrictions.- How to upgrade: add
asyncto the function definition of all actor lifecycle methods.
- How to upgrade: add
Actornow requiresSendto implement. Previously, the trait itself did not, but using it did requireSend.- How to upgrade: you probably never had a non-
Sendactor in the first place.
- How to upgrade: you probably never had a non-
- The
{Weak}Address::attach_streammethod now requires that the actor implementsHandler<M>whereM: Into<KeepRunning> + Send. This is automatically implemented for(), returningKeepRunning::Yes. This allows the user more control over the future spawned byattach_stream, but is breaking if the message returned did not implementInto<KeepRunning>/- How to upgrade: implement
Into<KeepRunning>for all message types used inattach_stream. To mimic previous behaviour, returnKeepRunning::Yesin the implementation.
- How to upgrade: implement
See the full list of breaking changes by version here