pub struct Client { /* private fields */ }Expand description
Connected client. One stream; notifications arriving during Self::request
are handed to the optional callback.
Implementations§
Source§impl Client
impl Client
Sourcepub fn connect(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn connect(path: impl AsRef<Path>) -> Result<Self, Error>
Connect to path. Uses JSONL framing.
§Errors
Returns an error when the socket cannot be opened or cloned.
Sourcepub fn connect_with_framing(
path: impl AsRef<Path>,
framing: Framing,
) -> Result<Self, Error>
pub fn connect_with_framing( path: impl AsRef<Path>, framing: Framing, ) -> Result<Self, Error>
Connect and send every request in framing. The owner replies in kind.
§Errors
Returns an error when the socket cannot be opened or cloned.
Sourcepub fn on_notification<F>(&mut self, callback: F)
pub fn on_notification<F>(&mut self, callback: F)
Called for each JSON-RPC notification read while waiting on a response.
Sourcepub fn request(&mut self, method: &str, params: Value) -> Result<Value, Error>
pub fn request(&mut self, method: &str, params: Value) -> Result<Value, Error>
Send method/params and return the result object.
§Errors
Returns an error when the write or read fails, the payload is not JSON, the response id does not match, or the server returns a JSON-RPC error.
Sourcepub fn request_typed(&mut self, req: &Request) -> Result<Value, Error>
pub fn request_typed(&mut self, req: &Request) -> Result<Value, Error>
Typed request helper. Result is the raw JSON body (caller decodes).
§Errors
Returns an error when the write or read fails, the payload is not JSON, the response id does not match, or the server returns a JSON-RPC error.
Sourcepub fn notify(&mut self, method: &str, params: Value) -> Result<(), Error>
pub fn notify(&mut self, method: &str, params: Value) -> Result<(), Error>
Send a notification (no id). Does not wait.
§Errors
Returns an error when the notification cannot be encoded or written.
Sourcepub fn wait_notification(
&mut self,
timeout: Duration,
) -> Result<Notification, Error>
pub fn wait_notification( &mut self, timeout: Duration, ) -> Result<Notification, Error>
Block until the next JSON-RPC notification, or timeout.
§Errors
Returns an error when the wait times out, the read or decode fails, or the next message is a response rather than a notification.