[][src]Struct zvariant::SharedData

pub struct SharedData { /* fields omitted */ }

Immutable slice of an underlying byte buffer.

Cloning this is cheap as it does not clone the underlying buffer.

Example

use zvariant::SharedData;

let data = SharedData::from((0u8..10).collect::<Vec<_>>());
assert!(data.position() == 0);
assert!(data.end() == 10);
assert!(data.len() == 10);

let subset1 = data.subset(2, 8);
assert!(subset1.position() == 2);
assert!(subset1.end() == 8);
assert!(subset1.len() == 6);

let subset3 = data.head(7);
assert!(subset3.position() == 0);
assert!(subset3.end() == 7);
assert!(subset3.len() == 7);

let subset4 = subset3.tail(3);
assert!(subset4.position() == 3);
assert!(subset4.end() == 7);
assert!(subset4.len() == 4);

Methods

impl SharedData[src]

pub fn new(data: Vec<u8>) -> Self[src]

Create a new SharedData.

pub fn subset(&self, index: usize, end: usize) -> Self[src]

Create a new slice of self, from index to (but excluding) end.

Panics

  • index >= end
  • end == 0
  • end > self.end()

pub fn head(&self, len: usize) -> Self[src]

Create a new slice of self, containing the first len bytes.

Panics

  • len == 0
  • len > self.end()

pub fn tail(&self, index: usize) -> Self[src]

Create a new slice of self, containing bytes after index.

Panics

  • index >= self.end()

pub fn position(&self) -> usize[src]

Get the position of this slice in the whole underlying buffer.

pub fn end(&self) -> usize[src]

Get the end of this slice in the whole underlying buffer.

pub fn len(&self) -> usize[src]

Get the length of self.

pub fn bytes(&self) -> &[u8][src]

Get the raw byte slice of self.

Trait Implementations

impl Clone for SharedData[src]

impl Debug for SharedData[src]

impl Display for SharedData[src]

impl<'_> From<&'_ SharedData> for SharedData[src]

Same as cloning

impl From<Vec<u8>> for SharedData[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.