pub struct JsonRpcEnvelope {
pub id: Option<JsonRpcId>,
pub method: Option<String>,
pub params: Option<Box<RawValue>>,
pub result: Option<Box<RawValue>>,
pub error: Option<JsonRpcError>,
}Expand description
Shallow parse of a single JSON-RPC 2.0 message.
Fields§
§id: Option<JsonRpcId>§method: Option<String>§params: Option<Box<RawValue>>§result: Option<Box<RawValue>>§error: Option<JsonRpcError>Implementations§
Source§impl JsonRpcEnvelope
impl JsonRpcEnvelope
Sourcepub fn parse(bytes: &[u8]) -> Result<Self, ParseError>
pub fn parse(bytes: &[u8]) -> Result<Self, ParseError>
Parse a single JSON-RPC 2.0 message. Rejects batches.
Sourcepub fn params_as<T: DeserializeOwned>(&self) -> Option<T>
pub fn params_as<T: DeserializeOwned>(&self) -> Option<T>
Deserialize params into T. Returns None if params is
absent or does not match T’s shape.
Sourcepub fn result_as<T: DeserializeOwned>(&self) -> Option<T>
pub fn result_as<T: DeserializeOwned>(&self) -> Option<T>
Deserialize result into T. Returns None if result is
absent or does not match T’s shape.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Reassemble the envelope into JSON-RPC 2.0 bytes.
Used when forwarding upstream (request body) and when sealing a
buffered response. The inner RawValue fields are re-inlined
verbatim — no re-parsing. Parse failures on the cached bytes
would have been caught by JsonRpcEnvelope::parse, so we
default to Null rather than panic.
Trait Implementations§
Source§impl Clone for JsonRpcEnvelope
impl Clone for JsonRpcEnvelope
Source§fn clone(&self) -> JsonRpcEnvelope
fn clone(&self) -> JsonRpcEnvelope
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for JsonRpcEnvelope
impl RefUnwindSafe for JsonRpcEnvelope
impl Send for JsonRpcEnvelope
impl Sync for JsonRpcEnvelope
impl Unpin for JsonRpcEnvelope
impl UnsafeUnpin for JsonRpcEnvelope
impl UnwindSafe for JsonRpcEnvelope
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