[−][src]Struct kserd::Barr
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]
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]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a> Ord for Barr<'a>
[src]
fn cmp(&self, other: &Barr<'a>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[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]
fn partial_cmp(&self, other: &Barr<'a>) -> Option<Ordering>
[src]
fn lt(&self, other: &Barr<'a>) -> bool
[src]
fn le(&self, other: &Barr<'a>) -> bool
[src]
fn gt(&self, other: &Barr<'a>) -> bool
[src]
fn ge(&self, other: &Barr<'a>) -> bool
[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]
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, 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>,