[][src]Struct kserd::Barr

pub struct Barr<'a> {
    pub inner: Cow<'a, [u8]>,
}

An owned or borrowed byte array.

Barr provides a thin wrapper around Cow<u8>. The smart pointer allows the byte array to be borrowed up until the point of mutation, at which point a clone is made.

Fields

inner: Cow<'a, [u8]>

Inner access to the underlying clone-on-write smart pointer.

Methods

impl<'a> Barr<'a>[src]

pub const fn brwed(bytes: &'a [u8]) -> Self[src]

A new borrowed byte array. Barr has the same lifetime as the borrowed data.

pub const fn owned(bytes: Vec<u8>) -> Barr<'static>[src]

A new owned byte array. Takes ownership of the vector of bytes and has a 'static lifetime.

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

Represent the byte array as a slice.

Example

let barr = Barr::owned(vec![0,1,2]);
assert_eq!(barr.as_bytes(), &[0,1,2]);

pub fn to_mut(&mut self) -> &mut Vec<u8>[src]

Acquires a mutable reference to the owned vector of bytes.

Allocates a new vector and clones the data if not already owned.

Example

let mut barr = Barr::brwed([0,1,2,3].as_ref());
barr.to_mut().push(4);
assert_eq!(barr, Barr::brwed([0,1,2,3,4].as_ref()));

pub fn into_owned(self) -> Barr<'static>[src]

Makes the underlying byte array owned.

Allocates a new vector and clones the data if it is not already owned. This upgrades the lifetime to 'static.

Example

let mut barr = Barr::brwed([0,1,2,3].as_ref());    
assert_eq!(barr.to_owned(), Barr::owned(vec![0,1,2,3]));

Trait Implementations

impl<'a> AsRef<[u8]> for Barr<'a>[src]

impl<'a> Clone for Barr<'a>[src]

impl<'a> Debug for Barr<'a>[src]

impl<'a> Deref for Barr<'a>[src]

type Target = [u8]

The resulting type after dereferencing.

impl<'a> Eq for Barr<'a>[src]

impl<'a> From<&'a [u8]> for Barr<'a>[src]

impl From<Vec<u8>> for Barr<'static>[src]

impl<'a> Hash for Barr<'a>[src]

impl<'a> Ord for Barr<'a>[src]

impl<'a> PartialEq<[u8]> for Barr<'a>[src]

impl<'a, '_> PartialEq<[u8]> for &'_ Barr<'a>[src]

impl<'a> PartialEq<Barr<'a>> for Barr<'a>[src]

impl<'a> PartialOrd<Barr<'a>> for Barr<'a>[src]

impl<'a> StructuralEq for Barr<'a>[src]

impl<'a> StructuralPartialEq for Barr<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Barr<'a>

impl<'a> Send for Barr<'a>

impl<'a> Sync for Barr<'a>

impl<'a> Unpin for Barr<'a>

impl<'a> UnwindSafe for Barr<'a>

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