Skip to main content

Complex

Struct Complex 

Source
pub struct Complex<Message> {
    pub data: Bytes,
    pub message: OnceLock<Message>,
}
Expand description

A lazy-deserialized message.

It holds the raw wire bytes (data) and only parses them into a Message on first access, caching the result in a OnceLock. When written out, BinWrite emits the original raw bytes and never re-serializes.

§Why it is fast

  • No parse cost unless needed. A message that is only forwarded or logged is never deserialized, so it skips the full decode cost entirely.
  • No re-serialize cost. Writing emits the stored raw bytes, avoiding a re-encode of the already-parsed message.
  • Cheap clone. Cloning copies only the reference-counted Bytes and resets the cache, so it does not deep-copy the message. super_clone is used when the cached message must also be cloned.

Fields§

§data: Bytes

The raw wire bytes of the message.

§message: OnceLock<Message>

The lazily-parsed message cache.

Implementations§

Source§

impl<Message> Complex<Message>

Source

pub fn new(data: Bytes) -> Self

Create a Complex from raw wire bytes, without parsing.

Source

pub fn super_clone(&self) -> Self
where Message: Clone,

Clone the Complex, including the cached message if present.

Source

pub fn bytes(&self) -> &Bytes

Get a reference to the raw wire bytes.

Source§

impl<Message> Complex<Message>
where Message: BinWrite, for<'a> <Message as BinWrite>::Args<'a>: Default,

Source

pub fn from_message(message: Message) -> Self

Create a Complex from a parsed message, serializing it to raw bytes.

Source§

impl<Message: BinRead> Complex<Message>
where for<'a> <Message as BinRead>::Args<'a>: Default,

Source

pub fn try_get(&self) -> Result<&Message, Error>

Parse the message from the raw bytes on first access, caching it.

Source

pub fn into_inner(self) -> Option<Message>

Consume the Complex, returning the cached message if it was parsed.

Trait Implementations§

Source§

impl<Message: BinWrite> BinWrite for Complex<Message>

Source§

type Args<'a> = <Message as BinWrite>::Args<'a>

The type used for the args parameter of write_args() and write_options(). Read more
Source§

fn write_options<W: Write>( &self, writer: &mut W, _endian: Endian, _args: Self::Args<'_>, ) -> BinResult<()>

Write Self to the writer using the given Endian and arguments. Read more
Source§

fn write_be<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek, Self::Args<'a>: for<'a> Required,

Write Self to the writer assuming big-endian byte order. Read more
Source§

fn write_le<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek, Self::Args<'a>: for<'a> Required,

Write Self to the writer assuming little-endian byte order. Read more
Source§

fn write_be_args<W>( &self, writer: &mut W, args: Self::Args<'_>, ) -> Result<(), Error>
where W: Write + Seek,

Write Self to the writer, assuming big-endian byte order, using the given arguments. Read more
Source§

fn write_le_args<W>( &self, writer: &mut W, args: Self::Args<'_>, ) -> Result<(), Error>
where W: Write + Seek,

Write Self to the writer, assuming little-endian byte order, using the given arguments. Read more
Source§

impl<Message> Clone for Complex<Message>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Message: Debug> Debug for Complex<Message>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Message: BinRead> Deref for Complex<Message>
where for<'a> <Message as BinRead>::Args<'a>: Default,

Source§

type Target = Message

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<Message> From<&Complex<Message>> for MessageType

Source§

fn from(value: &Complex<Message>) -> Self

Converts to this type from the input type.
Source§

impl<Message> From<&Complex<Message>> for MessageType

Source§

fn from(value: &Complex<Message>) -> Self

Converts to this type from the input type.
Source§

impl<Message> From<&Complex<Message>> for MessageType

Source§

fn from(value: &Complex<Message>) -> Self

Converts to this type from the input type.
Source§

impl<Message: BinRead> From<Bytes> for Complex<Message>
where for<'a> <Message as BinRead>::Args<'a>: Default,

Source§

fn from(bytes: Bytes) -> Self

Converts to this type from the input type.
Source§

impl<Message> From<Message> for Complex<Message>
where Message: BinRead + BinWrite + PureMessage, for<'a> <Message as BinRead>::Args<'a>: Default, for<'a> <Message as BinWrite>::Args<'a>: Default,

Source§

fn from(message: Message) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Message> !Freeze for Complex<Message>

§

impl<Message> RefUnwindSafe for Complex<Message>
where OnceLock<Message>: RefUnwindSafe,

§

impl<Message> Send for Complex<Message>
where OnceLock<Message>: Send,

§

impl<Message> Sync for Complex<Message>
where OnceLock<Message>: Sync,

§

impl<Message> Unpin for Complex<Message>
where OnceLock<Message>: Unpin,

§

impl<Message> UnsafeUnpin for Complex<Message>
where OnceLock<Message>: UnsafeUnpin,

§

impl<Message> UnwindSafe for Complex<Message>
where OnceLock<Message>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.