pub struct JsonRpcClient<T: Transport> { /* private fields */ }Expand description
JSON-RPC 2.0 client with bidirectional communication.
Features:
- Send requests and await responses (with timeout)
- Send notifications (fire-and-forget)
- Handle incoming notifications via callback
- Handle incoming requests (server-to-client calls) via callback
- Background read loop with automatic dispatch
Implementations§
Source§impl<T: Transport + 'static> JsonRpcClient<T>
impl<T: Transport + 'static> JsonRpcClient<T>
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if client is running.
Sourcepub async fn set_notification_handler<F>(&self, handler: F)
pub async fn set_notification_handler<F>(&self, handler: F)
Set handler for incoming notifications.
Sourcepub async fn set_request_handler<F>(&self, handler: F)
pub async fn set_request_handler<F>(&self, handler: F)
Set handler for incoming requests.
Sourcepub async fn invoke(&self, method: &str, params: Option<Value>) -> Result<Value>
pub async fn invoke(&self, method: &str, params: Option<Value>) -> Result<Value>
Send a request and await response.
Sourcepub async fn invoke_with_timeout(
&self,
method: &str,
params: Option<Value>,
timeout: Duration,
) -> Result<Value>
pub async fn invoke_with_timeout( &self, method: &str, params: Option<Value>, timeout: Duration, ) -> Result<Value>
Send a request with custom timeout.
Sourcepub async fn notify(&self, method: &str, params: Option<Value>) -> Result<()>
pub async fn notify(&self, method: &str, params: Option<Value>) -> Result<()>
Send a notification (no response expected).
Sourcepub async fn send_response(&self, id: JsonRpcId, result: Value) -> Result<()>
pub async fn send_response(&self, id: JsonRpcId, result: Value) -> Result<()>
Send a response to an incoming request.
Sourcepub async fn send_error_response(
&self,
id: JsonRpcId,
error: JsonRpcError,
) -> Result<()>
pub async fn send_error_response( &self, id: JsonRpcId, error: JsonRpcError, ) -> Result<()>
Send an error response to an incoming request.
Auto Trait Implementations§
impl<T> !Freeze for JsonRpcClient<T>
impl<T> !RefUnwindSafe for JsonRpcClient<T>
impl<T> Send for JsonRpcClient<T>
impl<T> Sync for JsonRpcClient<T>
impl<T> Unpin for JsonRpcClient<T>
impl<T> UnsafeUnpin for JsonRpcClient<T>
impl<T> !UnwindSafe for JsonRpcClient<T>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more