[−][src]Struct zvariant::SharedData
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]
pub fn tail(&self, index: usize) -> Self
[src]
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]
fn clone(&self) -> SharedData
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for SharedData
[src]
impl Display for SharedData
[src]
impl<'_> From<&'_ SharedData> for SharedData
[src]
Same as cloning
fn from(value: &SharedData) -> Self
[src]
impl From<Vec<u8>> for SharedData
[src]
Auto Trait Implementations
impl !RefUnwindSafe for SharedData
impl !Send for SharedData
impl !Sync for SharedData
impl Unpin for SharedData
impl UnwindSafe for SharedData
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,