pub struct PayloadBytes<T = ()> { /* private fields */ }Expand description
Payload and bytes.
Stores the payload value as interpreted by the application (type T) and
the original payload bytes.
The original payload bytes are always preserved since they can not always be deterministically (or cheaply) reconstructed from the typed payload value.
Implementations§
Source§impl PayloadBytes
impl PayloadBytes
Sourcepub fn from_bytes(bytes: Vec<u8>) -> Self
pub fn from_bytes(bytes: Vec<u8>) -> Self
Creates a new PayloadBytes from the bytes.
The interpretation of the bytes will be unit ().
Source§impl<T: CosePayload> PayloadBytes<T>
impl<T: CosePayload> PayloadBytes<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Creates a new PayloadBytes from the payload, using
CosePayload::payload_bytes to reconstruct the payload bytes.
Source§impl<T> PayloadBytes<T>
impl<T> PayloadBytes<T>
Sourcepub fn map<U>(self, f: impl FnOnce(T, &[u8]) -> U) -> PayloadBytes<U>
pub fn map<U>(self, f: impl FnOnce(T, &[u8]) -> U) -> PayloadBytes<U>
Maps the payload interpretation.
This function can be used to decode the raw payload bytes into a proper typed value the application can work with.
Sourcepub fn try_map<U, E>(
self,
f: impl FnOnce(T, &[u8]) -> Result<U, E>,
) -> Result<PayloadBytes<U>, E>
pub fn try_map<U, E>( self, f: impl FnOnce(T, &[u8]) -> Result<U, E>, ) -> Result<PayloadBytes<U>, E>
Tries to map the payload interpretation.
This function can be used to decode the raw payload bytes into a proper typed value the application can work with.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Forgets about the payload interpretation and returns the raw bytes.
Trait Implementations§
Source§impl<T> Borrow<T> for PayloadBytes<T>
impl<T> Borrow<T> for PayloadBytes<T>
Source§impl<T: Clone> Clone for PayloadBytes<T>
impl<T: Clone> Clone for PayloadBytes<T>
Source§fn clone(&self) -> PayloadBytes<T>
fn clone(&self) -> PayloadBytes<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Deref for PayloadBytes<T>
impl<T> Deref for PayloadBytes<T>
Source§impl<T: PartialEq> PartialEq for PayloadBytes<T>
impl<T: PartialEq> PartialEq for PayloadBytes<T>
impl<T> StructuralPartialEq for PayloadBytes<T>
Auto Trait Implementations§
impl<T> Freeze for PayloadBytes<T>where
T: Freeze,
impl<T> RefUnwindSafe for PayloadBytes<T>where
T: RefUnwindSafe,
impl<T> Send for PayloadBytes<T>where
T: Send,
impl<T> Sync for PayloadBytes<T>where
T: Sync,
impl<T> Unpin for PayloadBytes<T>where
T: Unpin,
impl<T> UnwindSafe for PayloadBytes<T>where
T: UnwindSafe,
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> BorrowUnordered for T
impl<T> BorrowUnordered for T
fn as_unordered(&self) -> &Unordered<T>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, U, C> IntoWithContext<U, C> for Twhere
U: FromWithContext<T, C>,
impl<T, U, C> IntoWithContext<U, C> for Twhere
U: FromWithContext<T, C>,
Source§impl<T> ResourceProvider<()> for T
impl<T> ResourceProvider<()> for T
Source§fn get_resource(&self) -> &()
fn get_resource(&self) -> &()
T.