Enum Message
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§
§impl Message
impl Message
pub fn from_json(bytes: &[u8]) -> Result<Message, MessageDecodeError>
pub fn from_json(bytes: &[u8]) -> Result<Message, 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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