Struct structbuf::Unpacker

source ·
#[repr(transparent)]
pub struct Unpacker<'a>(_);
Expand description

Unpacker of POD values from a byte slice.

Any reads past the end of the slice return default values rather than panicking. The caller must check the error status at the end to determine whether all returned values were valid.

Little-endian encoding is assumed.

Implementations§

Creates a new unpacker.

Returns the remaining byte slice or None if any reads went past the end of the original slice.

Returns the remaining number of bytes.

Returns whether the byte slice is empty.

Returns whether all reads were within the bounds of the original byte slice.

Returns the remaining byte slice in a new unpacker, leaving self empty. This is primarily useful in combination with map().

Returns Some output of f, or None if f fails to consume the entire slice without reading past the end.

Returns the output of f, or default if f fails to consume the entire slice without reading past the end.

Returns the output of f, or the output of default() if f fails to consume the entire slice without reading past the end.

Splits the remaining byte slice at i, and returns two new unpackers, both of which will be in an error state if len() < i.

Advances self by n bytes, returning a new unpacker for the skipped bytes or None if there is an insufficient number of bytes remaining, in which case any remaining bytes are discarded.

Examples
if let Some(mut hdr) = p.skip(2) {
    let _ = hdr.u16();
    assert!(hdr.is_ok() && p.is_ok());
} else {
    assert!(!p.is_ok());
}

Returns the next u8 as a bool where any non-zero value is converted to true.

Returns the next u8.

Returns the next u16.

Returns the next u32.

Returns the next u64.

Returns the next u128.

Returns the next i8.

Returns the next i16.

Returns the next i32.

Returns the next i64.

Returns the next i128.

Returns the next T, or T::default() if there is an insufficient number of bytes remaining, in which case any remaining bytes are discarded.

Safety

T must be able to hold the resulting bit pattern.

Trait Implementations§

Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Returns an unpacker for reading values from the start of the buffer.