Expand description
§RuaPC - A High-Performance Rust RPC Library
RuaPC is a versatile RPC (Remote Procedure Call) library that supports multiple transport protocols including TCP, WebSocket, HTTP, and optionally RDMA (Remote Direct Memory Access).
§Features
- Multiple Transport Protocols: TCP, WebSocket, HTTP, RDMA (optional), and a unified protocol
- Multiple Serialization Formats: JSON (default) and MessagePack support
- OpenAPI Integration: Automatic OpenAPI 3.0 specification generation
- Type Safety: Strongly typed service definitions with compile-time validation
- Async/Await: Built on tokio for efficient asynchronous I/O
§Quick Start
§Define a Service
ⓘ
use ruapc::{Context, Result};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
pub struct Request(pub String);
#[ruapc::service]
pub trait EchoService {
async fn echo(&self, c: &Context, r: &Request) -> Result<String>;
}§Implement and Start a Server
ⓘ
use std::{net::SocketAddr, str::FromStr, sync::Arc};
struct DemoImpl;
impl EchoService for DemoImpl {
async fn echo(&self, _c: &Context, r: &Request) -> Result<String> {
Ok(r.0.clone())
}
}
#[tokio::main]
async fn main() {
let demo = Arc::new(DemoImpl);
let mut router = Router::default();
EchoService::ruapc_export(demo.clone(), &mut router);
let server = Server::create(router, &SocketPoolConfig::default()).unwrap();
let server = Arc::new(server);
let addr = SocketAddr::from_str("127.0.0.1:8000").unwrap();
let addr = server.listen(addr).await.unwrap();
println!("Serving on {addr}...");
server.join().await
}§Create a Client
ⓘ
use std::{net::SocketAddr, str::FromStr};
#[tokio::main]
async fn main() {
let addr = SocketAddr::from_str("127.0.0.1:8000").unwrap();
let ctx = Context::create(&SocketPoolConfig::default()).unwrap().with_addr(addr);
let client = Client::default();
let rsp = client.echo(&ctx, &Request("Rua!".into())).await;
println!("echo rsp: {:?}", rsp);
}Modules§
- http
- HTTP transport implementation.
- services
- Built-in services (MetaService, RdmaService). Built-in RPC services.
- tcp
- TCP transport implementation.
- unified
- Unified transport that supports multiple protocols simultaneously.
- ws
- WebSocket transport implementation.
Structs§
- Client
- RPC client configuration and request handler.
- Context
- RPC context carrying request metadata and connection information.
- Error
- RPC error type containing error kind and optional message.
- Listener
- Network listener for accepting incoming connections.
- Message
- RPC message containing metadata and payload.
- MsgFlags
- Message flags for RPC communication.
- MsgMeta
- Message metadata containing routing and control information.
- Router
- Service method router and registry.
- Server
- RPC server that listens for and handles incoming requests.
- Socket
Pool Config - Socket pool configuration.
- State
- Shared state for the RPC system.
- Task
Supervisor - Task lifecycle supervisor for graceful shutdown.
- Waiter
- Response waiter for correlating RPC requests with responses.
- Waiter
Cleaner - RAII guard for automatic cleanup of waiter entries.
Enums§
- Error
Kind - Error kinds representing different failure scenarios in RPC operations.
- Payload
- Message payload supporting different memory backends.
- RawStream
- Raw network stream types.
- Socket
- Socket abstraction supporting multiple transport protocols.
- Socket
Endpoint - Socket endpoint information for RPC contexts.
- Socket
Pool - Socket pool managing connections for different transport protocols.
- Socket
Type - Transport protocol types supported by RuaPC.
Traits§
- Socket
Pool Trait - Trait defining the interface for socket pool management.
- Socket
Trait - Trait defining the interface for sending messages through different socket types.
Type Aliases§
Attribute Macros§
- service
- Procedural macro for defining RPC services.