genserver: generate a server
genserver is tiny async actor framework, inspired by Elixir's GenServer. With few lines code, we do great things.
Check out the docs for more details.
This library is a great choice if you need an small async actor framework that doesn't get up in your face and has the features you need without all the cruft you don't. This crate has the added advantage of being insanely fast, and comes with all of Rust's safety features.
This code is 100% pure-Rust, with no unsafe code anywhere. It has minimal dependencies to keep your compile times short.
Every server you make and launch with the GenServer
trait will spawn its own
loop to handle incoming messages. You can make as many servers as you'd like,
and they can all talk to each other by keeping a copy of the registry generated
with #[make_registry{}]
. The registry can be cloned into different threads,
and it's safe to send messages from anywhere within the same runtime.
Synopsis
First, add the crate as a dependency:
$ cargo add genserver
Then, try this code here in your crate (note the 2 features which need to be
enabled in main.rs
or lib.rs
for applications and libraries respectively):
// these two features must be enabled at the crate level
use Future;
use ;
;
// When the registry goes out of scope, everything will shut down. You have to
// keep the registry in scope as long as you want it to continue running.
spawn;