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§
Implementations§
Source§impl ArcPayload
impl ArcPayload
Sourcepub fn new(data: Arc<[u8]>, start: usize, length: usize) -> Self
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 datastart
- The starting offset within the datalength
- 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"
Sourcepub fn as_slice(&self) -> &[u8] ⓘ
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
Sourcepub fn len(&self) -> usize
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
Sourcepub fn is_empty(&self) -> bool
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
Sourcepub fn arc_data(&self) -> Option<&Arc<[u8]>>
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
impl Clone for ArcPayload
Source§fn clone(&self) -> ArcPayload
fn clone(&self) -> ArcPayload
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ArcPayload
impl Debug for ArcPayload
Source§impl Default for ArcPayload
impl Default for ArcPayload
Source§impl IntoPayload for ArcPayload
Identity conversion for ArcPayload
(no-op)
impl IntoPayload for ArcPayload
Identity conversion for ArcPayload
(no-op)
Source§fn into_payload(self) -> ArcPayload
fn into_payload(self) -> ArcPayload
ArcPayload
Read moreSource§impl PartialEq for ArcPayload
impl PartialEq for ArcPayload
Source§impl Serialize for ArcPayload
impl Serialize for ArcPayload
impl Eq for ArcPayload
Auto Trait Implementations§
impl Freeze for ArcPayload
impl RefUnwindSafe for ArcPayload
impl Send for ArcPayload
impl Sync for ArcPayload
impl Unpin for ArcPayload
impl UnwindSafe for ArcPayload
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.