pub struct Packet<T> { /* private fields */ }web03 only.Expand description
A typed packet of data.
Implementations§
Source§impl<T> Packet<T>
impl<T> Packet<T>
Sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Construct an empty package.
§Examples
use musli_web::api::MessageId;
use musli_web::web::Packet;
let packet = Packet::<()>::empty();
assert!(packet.is_empty());
assert_eq!(packet.id(), MessageId::EMPTY);Sourcepub fn new(raw: RawPacket) -> Self
pub fn new(raw: RawPacket) -> Self
Construct a new typed package from a raw one.
Note that this does not guarantee that the typed package is correct, but
the T parameter becomes associated with it allowing it to be used
automatically with methods such as Packet::decode.
Sourcepub fn into_raw(self) -> RawPacket
pub fn into_raw(self) -> RawPacket
Convert a packet into a raw packet.
To determine which endpoint or broadcast it belongs to the
RawPacket::id method can be used.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if the packet is empty.
§Examples
use musli_web::web::Packet;
let packet = Packet::<()>::empty();
assert!(packet.is_empty());Sourcepub fn id(&self) -> MessageId
pub fn id(&self) -> MessageId
The id of the packet this is a response to as specified by
Endpoint::ID or Broadcast::ID.
Source§impl<T> Packet<T>where
T: Decodable,
impl<T> Packet<T>where
T: Decodable,
Sourcepub fn decode(&self) -> Result<T::Type<'_>, Error>
pub fn decode(&self) -> Result<T::Type<'_>, Error>
Decode the contents of a packet.
This can be called multiple times if there are multiple payloads in sequence of the response.
You can check if the packet is empty using Packet::is_empty.
Sourcepub fn decode_any<'de, R>(&'de self) -> Result<R, Error>
pub fn decode_any<'de, R>(&'de self) -> Result<R, Error>
Decode any contents of a packet.
This can be called multiple times if there are multiple payloads in sequence of the response.
You can check if the packet is empty using Packet::is_empty.
Source§impl<T> Packet<T>where
T: Endpoint,
impl<T> Packet<T>where
T: Endpoint,
Sourcepub fn decode_response(&self) -> Result<T::Response<'_>, Error>
pub fn decode_response(&self) -> Result<T::Response<'_>, Error>
Decode the contents of a packet.
This can be called multiple times if there are multiple payloads in sequence of the response.
You can check if the packet is empty using Packet::is_empty.
Sourcepub fn decode_any_response<'de, R>(&'de self) -> Result<R, Error>
pub fn decode_any_response<'de, R>(&'de self) -> Result<R, Error>
Decode any contents of a packet.
This can be called multiple times if there are multiple payloads in sequence of the response.
You can check if the packet is empty using Packet::is_empty.
Source§impl<T> Packet<T>where
T: Broadcast,
impl<T> Packet<T>where
T: Broadcast,
Sourcepub fn decode_event<'de>(&'de self) -> Result<T::Event<'de>, Error>where
T: BroadcastWithEvent,
pub fn decode_event<'de>(&'de self) -> Result<T::Event<'de>, Error>where
T: BroadcastWithEvent,
Decode the primary event related to a broadcast.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Packet<T>
impl<T> !RefUnwindSafe for Packet<T>
impl<T> !Send for Packet<T>
impl<T> !Sync for Packet<T>
impl<T> Unpin for Packet<T>where
T: Unpin,
impl<T> !UnwindSafe for Packet<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.