pub struct WshRpcEngine {
inner: Mutex<EngineInner>,
output_tx: UnboundedSender<RpcMessage>,
}Expand description
Core RPC engine: handles incoming RPC requests, dispatches to registered command handlers, and manages request/response lifecycle.
Port of Go’s WshRpc from pkg/wshutil/wshrpc.go.
Fields§
§inner: Mutex<EngineInner>§output_tx: UnboundedSender<RpcMessage>Implementations§
Source§impl WshRpcEngine
impl WshRpcEngine
Sourcepub fn new() -> (Arc<Self>, UnboundedReceiver<RpcMessage>)
pub fn new() -> (Arc<Self>, UnboundedReceiver<RpcMessage>)
Create a new RPC engine. Returns the engine and a receiver for outgoing messages.
Sourcepub fn register_handler(
&self,
command: &str,
handler: Box<dyn Fn(Value, RpcContext) -> Pin<Box<dyn Future<Output = Result<Option<Value>, String>> + Send>> + Send + Sync>,
)
pub fn register_handler( &self, command: &str, handler: Box<dyn Fn(Value, RpcContext) -> Pin<Box<dyn Future<Output = Result<Option<Value>, String>> + Send>> + Send + Sync>, )
Register a call handler (single request → single response).
Sourcepub fn register_stream_handler(
&self,
command: &str,
handler: Box<dyn Fn(Value, RpcContext) -> Pin<Box<dyn Future<Output = Result<Receiver<Result<Option<Value>, String>>, String>> + Send>> + Send + Sync>,
)
pub fn register_stream_handler( &self, command: &str, handler: Box<dyn Fn(Value, RpcContext) -> Pin<Box<dyn Future<Output = Result<Receiver<Result<Option<Value>, String>>, String>> + Send>> + Send + Sync>, )
Register a streaming handler (single request → stream of responses).
Sourcepub fn set_auth_token(&self, token: &str)
pub fn set_auth_token(&self, token: &str)
Set the authentication token.
Sourcepub fn get_auth_token(&self) -> String
pub fn get_auth_token(&self) -> String
Get the authentication token.
Sourcepub fn set_rpc_context(&self, ctx: RpcContext)
pub fn set_rpc_context(&self, ctx: RpcContext)
Set the RPC context.
Sourcepub fn handle_message(self: &Arc<Self>, msg: RpcMessage)
pub fn handle_message(self: &Arc<Self>, msg: RpcMessage)
Process an incoming message (from the transport layer).
Sourcepub async fn send_command(
self: &Arc<Self>,
command: &str,
data: Value,
opts: &RpcOpts,
) -> Result<Value, String>
pub async fn send_command( self: &Arc<Self>, command: &str, data: Value, opts: &RpcOpts, ) -> Result<Value, String>
Send an RPC command and wait for a single response.
Sourcepub fn send_request(
self: &Arc<Self>,
command: &str,
data: Value,
opts: &RpcOpts,
) -> Result<RpcRequestHandler, String>
pub fn send_request( self: &Arc<Self>, command: &str, data: Value, opts: &RpcOpts, ) -> Result<RpcRequestHandler, String>
Send an RPC command and get a request handler for streaming responses.
Sourcepub fn send_command_no_response(&self, command: &str, data: Value, route: &str)
pub fn send_command_no_response(&self, command: &str, data: Value, route: &str)
Send a fire-and-forget command (no response expected).
fn send_output(&self, msg: RpcMessage)
async fn handle_request(self: Arc<Self>, msg: RpcMessage)
fn handle_response(&self, msg: RpcMessage)
fn handle_cancel_request(&self, req_id: &str)
fn cleanup_handler(&self, req_id: &str)
Auto Trait Implementations§
impl !Freeze for WshRpcEngine
impl RefUnwindSafe for WshRpcEngine
impl Send for WshRpcEngine
impl Sync for WshRpcEngine
impl Unpin for WshRpcEngine
impl UnwindSafe for WshRpcEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.