pub struct JsonRpcMessage {
pub jsonrpc: String,
pub id: Option<Value>,
pub method: Option<String>,
pub params: Option<Value>,
pub result: Option<Value>,
pub error: Option<JsonRpcError>,
}Expand description
A JSON-RPC 2.0 message: request, response, or notification depending on which fields are set.
id is a serde_json::Value rather than an integer so any id a host uses
(number or string, both legal) round-trips back verbatim in the response.
Fields§
§jsonrpc: StringAlways "2.0".
id: Option<Value>Request/response correlation id; absent on notifications.
method: Option<String>Method name; set on requests and notifications.
params: Option<Value>Method parameters.
result: Option<Value>Success payload; set on responses.
error: Option<JsonRpcError>Failure payload; set on error responses.
Implementations§
Source§impl JsonRpcMessage
impl JsonRpcMessage
Sourcepub fn response(id: Value, result: &impl Serialize) -> Self
pub fn response(id: Value, result: &impl Serialize) -> Self
A successful response to the request identified by id.
result is always one of this module’s protocol types, whose
serialization is infallible; a failure would be a bug here rather than a
runtime condition, so it degrades to JSON null instead of propagating.
Sourcepub fn error_response(id: Value, code: i32, message: impl Into<String>) -> Self
pub fn error_response(id: Value, code: i32, message: impl Into<String>) -> Self
An error response to the request identified by id.
Sourcepub fn notification(method: impl Into<String>, params: &impl Serialize) -> Self
pub fn notification(method: impl Into<String>, params: &impl Serialize) -> Self
An outbound notification (no id, no response expected).
Sourcepub fn request(
id: Value,
method: impl Into<String>,
params: &impl Serialize,
) -> Self
pub fn request( id: Value, method: impl Into<String>, params: &impl Serialize, ) -> Self
An outbound request (agent → client), e.g. session/request_permission.
Sourcepub fn is_notification(&self) -> bool
pub fn is_notification(&self) -> bool
Whether this message is a notification: a method call with no id, which must never be answered.
Trait Implementations§
Source§impl Clone for JsonRpcMessage
impl Clone for JsonRpcMessage
Source§fn clone(&self) -> JsonRpcMessage
fn clone(&self) -> JsonRpcMessage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more