pub struct OpaqueOpen<'a> { /* private fields */ }Expand description
An optional open variant with a stable numeric ID and opaque payload.
The first component is a Postcard u32. Its low bit selects a following nonempty Postcard byte span. The upper bits hold the ID, with zero reserved for absence. Unit variants have no payload length or payload bytes.
Implementations§
Source§impl<'a> OpaqueOpen<'a>
impl<'a> OpaqueOpen<'a>
Sourcepub const fn unit(id: u32) -> Result<Self, Error>
pub const fn unit(id: u32) -> Result<Self, Error>
Construct a present unit variant without using scratch storage.
§Errors
Returns malformed if the ID is zero or greater than 2³¹ minus one.
Sourcepub fn write<T: Serialize + ?Sized>(
context: &WriteContext<'_>,
id: u32,
value: &T,
scratch: &'a mut [u8],
) -> Result<Self, Error>
pub fn write<T: Serialize + ?Sized>( context: &WriteContext<'_>, id: u32, value: &T, scratch: &'a mut [u8], ) -> Result<Self, Error>
Write a typed open variant payload into scratch and borrow its extent.
§Errors
Returns an invalid ID, serialization, allowance or scratch capacity error.
Sourcepub fn write_in<T: Serialize + ?Sized>(
context: &WriteContext<'_>,
id: u32,
value: &T,
scratch: &'a mut [u8],
) -> Result<(Self, &'a mut [u8]), Error>
pub fn write_in<T: Serialize + ?Sized>( context: &WriteContext<'_>, id: u32, value: &T, scratch: &'a mut [u8], ) -> Result<(Self, &'a mut [u8]), Error>
Write a typed payload and return the open variant and unused scratch.
§Errors
Returns an invalid ID, serialization, allowance or scratch capacity error.
Sourcepub fn visit<R>(
self,
context: &ReadContext<'_>,
visit: impl FnOnce(u32, Field<'_, 'a>) -> Result<R, Error>,
) -> Result<Option<R>, Error>
pub fn visit<R>( self, context: &ReadContext<'_>, visit: impl FnOnce(u32, Field<'_, 'a>) -> Result<R, Error>, ) -> Result<Option<R>, Error>
Map a present selected tag, or keep absence.
The callback can ignore any tag its schema does not understand and decode a known tag’s entire payload. Known unit tags should decode the Rust unit value to reject a nonempty body.
§Errors
Returns any allowance or callback error.