pirates

Crates.iopirates
lib.rspirates
version0.1.2
sourcesrc
created_at2022-10-08 17:06:51.552004
updated_at2023-03-29 15:58:17.703606
descriptionSimple async RPC lib
homepagehttps://github.com/tehsmeely/pirates
repositoryhttps://github.com/tehsmeely/pirates
max_upload_size
id683648
size43,729
Jonty Heiser (tehsmeely)

documentation

README

Pirates!

pirate Rust ArrrrPC Lib

CI docs Current Crates.io Version

Pirates, a simple and straightforward interface for serving and calling RPCs from async rust programs

Define an RPC

    pub struct AddName {}
    #[pirates::rpc_definition]
    impl AddName {
        fn name() -> RpcId {
            RpcId::AddName
        }
        fn implement(state: &mut ServerState, query: String) -> RpcResult<()> {
            state.names.push(query);
            Ok(())
        }
    }

Serve it

    let mut server = RpcServer::new(state.clone());
    server.add_rpc(Box::new(rpcs::AddName::server()));

Call it

    let addr = "200.1.3.7:5959";
    let name = String::from("Gaspode the wonder dog");
    pirates::call_client(addr, name, rpcs::AddName::client()).await;

    let names = call_client(addr, (), rpcs::GetNames::client()).await;
    assert_eq!(vec![String::from("Gaspode the wonder dog")], names);

Documentation

Documentation available on docs.rs

Examples

And example "name server" is available in example/. This produces a CLI binary from which you can host the server and then query it separately to add and print names. See the README in that directory for more info

TODO

  • More examples?

License

Apache-2.0 Or MIT

Commit count: 63

cargo fmt