Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/znx3p0/srpc
- Owner: znx3p0
- Created: 2021-12-28T21:05:26.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-01-25T03:28:20.000Z (about 3 years ago)
- Last Synced: 2024-10-01T17:08:22.661Z (4 months ago)
- Topics: async, distributed-computing, distributed-systems, rpc, rpc-framework, rpc-library, rust
- Language: Rust
- Homepage:
- Size: 25.4 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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]`