mill_rpc_core/lib.rs
1//! Core types for Mill-RPC: wire protocol, codecs, errors, and dispatcher traits.
2
3pub mod codec;
4pub mod context;
5pub mod error;
6pub mod protocol;
7
8pub use codec::{Codec, CodecType};
9pub use context::RpcContext;
10pub use error::{RpcError, RpcStatus};
11pub use protocol::{Flags, Frame, FrameHeader, MessageType};
12
13/// Trait for dispatching RPC calls to handler methods.
14///
15/// This is auto-implemented by the `#[mill_rpc::service]` macro for any type
16/// that implements the generated `{Service}Server` trait.
17pub trait ServiceDispatch: Send + Sync + 'static {
18 fn dispatch(
19 &self,
20 ctx: &RpcContext,
21 method_id: u16,
22 args: &[u8],
23 codec: &Codec,
24 ) -> Result<Vec<u8>, RpcError>;
25}
26
27/// Trait for client-side RPC transport.
28///
29/// Abstracts the mechanism of sending a request and receiving a response.
30/// The main `mill-rpc` crate provides an implementation built on `mill-net`.
31pub trait RpcTransport: Send + Sync + 'static {
32 /// Send a request and wait for a response.
33 /// Returns the raw response payload bytes.
34 fn call(&self, service_id: u16, method_id: u16, payload: Vec<u8>) -> Result<Vec<u8>, RpcError>;
35}