ArcPayload

Enum ArcPayload 

Source
pub enum ArcPayload {
    Large {
        data: Arc<[u8]>,
        start: usize,
        length: usize,
    },
}
Expand description

A reference-counted byte payload with slice semantics

ArcPayload provides an efficient way to handle byte data by using Arc<[u8]> for reference counting, combined with offset and length information to represent a slice view of the underlying data. This allows for zero-copy sharing of payload data across multiple consumers while maintaining slice-like semantics.

Variants§

§

Large

Fields

§data: Arc<[u8]>
§start: usize
§length: usize

Implementations§

Source§

impl ArcPayload

Source

pub fn new(data: Arc<[u8]>, start: usize, length: usize) -> Self

Create a new ArcPayload from reference-counted data with specified range

Creates a new payload that represents a slice view of the provided Arc<[u8]> data starting at the specified offset with the given length.

§Parameters
  • data - The reference-counted byte data
  • start - The starting offset within the data
  • length - The length of the payload slice
§Panics

Panics in debug mode if start + length > data.len() (payload out of bounds)

§Examples
use alloc::sync::Arc;
use mqtt_protocol_core::mqtt::ArcPayload;

let data = Arc::from(&b"hello world"[..]);
let payload = ArcPayload::new(data, 0, 5); // "hello"
Source

pub fn as_slice(&self) -> &[u8]

Get a slice view of the payload data

Returns a byte slice representing the payload data within the specified range.

§Returns

A &[u8] slice of the payload data

Source

pub fn len(&self) -> usize

Get the length of the payload

Returns the number of bytes in the payload slice.

§Returns

The length of the payload in bytes

Source

pub fn is_empty(&self) -> bool

Check if the payload is empty

Returns true if the payload contains no bytes.

§Returns

true if the payload length is zero, false otherwise

Source

pub fn arc_data(&self) -> Option<&Arc<[u8]>>

Get a reference to the underlying Arc<[u8]> data

Returns a reference to the reference-counted byte array that contains the actual data. This provides access to the full underlying data, not just the slice view represented by this payload.

§Returns

A reference to the underlying Arc<[u8]> data

Trait Implementations§

Source§

impl Clone for ArcPayload

Source§

fn clone(&self) -> ArcPayload

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ArcPayload

Source§

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

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

impl Default for ArcPayload

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl IntoPayload for ArcPayload

Identity conversion for ArcPayload (no-op)

Source§

fn into_payload(self) -> ArcPayload

Convert the value into an ArcPayload Read more
Source§

impl PartialEq for ArcPayload

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ArcPayload

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for ArcPayload

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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<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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.