Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/znx3p0/srpc

Simple RPC system based on top of Canary
https://github.com/znx3p0/srpc

async distributed-computing distributed-systems rpc rpc-framework rpc-library rust

Last synced: 4 months ago
JSON representation

Simple RPC system based on top of Canary

Awesome Lists containing this project

README

        

# SRPC

SRPC is a simple RPC system built on top of [Canary](https://github.com/znx3p0/canary),
designed to be as ergonomic and zero-cost as possible.

A simple example of an SRPC service
```rust
#[srpc::rpc] // other options include rpc(mutex), rpc(none)
#[derive(Default)]
struct DistributedList {
list: Vec
}

#[srpc::rpc]
impl DistributedList {
async fn push(&mut self, value: T) {
self.list.push(value);
}
async fn get(&self, index: usize) -> Option {
self.list.get(index).and_then(|val| Some(val.clone()))
}
async fn remove(&mut self, index: usize) -> T {
self.list.remove(index)
}
}
```

```rust
// database
async fn main() -> Result<()> {
GLOBAL_ROUTE.add_service_at::>("list", Arc::new(RwLock::new(Default::default())))?;
let addr = "[email protected]:8080".parse::()?;
// listen in the following address
addr.bind().await?;
std::future::pending().await
}

// peer
async fn main() -> Result<()> {
let addr = "list://[email protected]:8080".parse::()?;
let connection = addr.connect().await?;
let mut db = connection.client::>();
db.push(1).await?;
db.push(5).await?;
db.push(6).await?;

let value = db.get(1).await?;
println!("{:?}", value); // index 1 == 5
Ok(())
}
```

SRPC also allows method attributes for flexibility.
The current attributes you can apply to methods are:
- `#[consume]`
- `#[server_consume]`
- `#[client_consume]`
- `#[server]`
- `#[client]`
- `#[manual]`