Enum RawData

Source
pub enum RawData<'a> {
    Single(&'a [u8]),
    Split(&'a [u8], &'a [u8]),
}
Expand description

A slice of u8 data that can have non-contiguous backing storage split into two pieces, and abstracts that split away so that users can pretend to deal with a contiguous slice.

When reading perf events from the mmap’d fd that contains the perf event stream, it often happens that a single record straddles the boundary between two mmap chunks, or is wrapped from the end to the start of a chunk.

Variants§

§

Single(&'a [u8])

§

Split(&'a [u8], &'a [u8])

Implementations§

Source§

impl<'a> RawData<'a>

Source

pub fn empty() -> Self

Source

pub fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Source

pub fn read_u64<T: ByteOrder>(&mut self) -> Result<u64, Error>

Source

pub fn read_u32<T: ByteOrder>(&mut self) -> Result<u32, Error>

Source

pub fn read_i32<T: ByteOrder>(&mut self) -> Result<i32, Error>

Source

pub fn read_u16<T: ByteOrder>(&mut self) -> Result<u16, Error>

Source

pub fn read_u8(&mut self) -> Result<u8, Error>

Source

pub fn read_string(&mut self) -> Option<RawData<'a>>

Finds the first nul byte. Returns everything before that nul byte. Sets self to everything after the nul byte.

Source

pub fn split_off_prefix(&mut self, n: usize) -> Result<Self, Error>

Returns the first n bytes, and sets self to the remainder.

Source

pub fn skip(&mut self, n: usize) -> Result<(), Error>

Source

pub fn as_slice(&self) -> Cow<'a, [u8]>

Source

pub fn get(&self, range: Range<usize>) -> Option<RawData<'a>>

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Trait Implementations§

Source§

impl<'a> Clone for RawData<'a>

Source§

fn clone(&self) -> RawData<'a>

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RawData<'_>

Source§

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

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

impl<'a> From<&'a [u8]> for RawData<'a>

Source§

fn from(bytes: &'a [u8]) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Cow<'a, [u8]>> for RawData<'a>

Source§

fn from(data: &'a Cow<'a, [u8]>) -> Self

Converts to this type from the input type.
Source§

impl<'a> PartialEq for RawData<'a>

Source§

fn eq(&self, other: &RawData<'a>) -> bool

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

const 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<'a> Copy for RawData<'a>

Source§

impl<'a> Eq for RawData<'a>

Source§

impl<'a> StructuralPartialEq for RawData<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for RawData<'a>

§

impl<'a> RefUnwindSafe for RawData<'a>

§

impl<'a> Send for RawData<'a>

§

impl<'a> Sync for RawData<'a>

§

impl<'a> Unpin for RawData<'a>

§

impl<'a> UnwindSafe for RawData<'a>

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<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.