pub struct Envelope<'a> { /* private fields */ }Expand description
One JSON-RPC message, borrowed from the frame buffer.
kind is the validated shape. The other fields are what the sender wrote,
kept as they arrived — a method is Some on a request and a notification
and None on a reply, and the two are the only way to tell those apart
without consulting kind, which is why kind exists.
No PartialEq, for the reason on WireError.
Implementations§
Source§impl<'a> Envelope<'a>
impl<'a> Envelope<'a>
Sourcepub const fn kind(&self) -> MessageKind
pub const fn kind(&self) -> MessageKind
The shape this message was decoded as.
Sourcepub const fn id(&self) -> Option<&WireId<'a>>
pub const fn id(&self) -> Option<&WireId<'a>>
The id, absent on a notification.
By reference: an id whose text had to be unescaped owns a String, and
returning it by value would clone that on every read. The common
unescaped case borrows, so a clone there would be a refcount bump on
nothing — either way the caller only wanted to look at it.
Sourcepub fn method_str(&self) -> Option<&str>
pub fn method_str(&self) -> Option<&str>
The method as a plain string, whichever arm of the Cow it is.
Sourcepub const fn params(&self) -> Option<&'a RawValue>
pub const fn params(&self) -> Option<&'a RawValue>
The params, still undecoded.
Borrowed raw JSON on purpose: the concrete type depends on the method and the negotiated revision, and neither is known until after routing. Decoding here would mean decoding every frame’s params even for methods that are about to be refused for not existing.
Sourcepub const fn outcome(&self) -> Option<&Outcome<'a>>
pub const fn outcome(&self) -> Option<&Outcome<'a>>
The reply half, present only on a Result or an Error.
Sourcepub const fn expects_reply(&self) -> bool
pub const fn expects_reply(&self) -> bool
Whether a reply is expected.