pub enum Message {
Request(Request),
Response(Response),
Notification(Notification),
}Expand description
One incoming or outgoing JSON-RPC message. The codec yields
Message from the wire; the actor matches on the variant.
We tag variants by the presence of id and method:
- request:
id+method - response:
id+ (resultxorerror), nomethod - notification:
method, noid
The custom deserialize (rather than #[serde(untagged)])
avoids an O(n²) try-each-variant pattern for every incoming
blob and gives precise error messages.
Variants§
Request(Request)
Has id and method: expects a Response.
Response(Response)
Has id and result / error, no method.
Notification(Notification)
Has method, no id: fire-and-forget.
Implementations§
Source§impl Message
impl Message
Sourcepub fn from_json(bytes: &[u8]) -> Result<Self, MessageDecodeError>
pub fn from_json(bytes: &[u8]) -> Result<Self, MessageDecodeError>
Decode one JSON-RPC message from a UTF-8 JSON byte slice.
Returns the typed variant; structurally invalid input
(missing both id and method, etc.) returns
MessageDecodeError::Malformed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
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