[][src]Struct squash::OwnedSlice

pub struct OwnedSlice<T, H = BoxHeader> where
    H: Header
{ /* fields omitted */ }

An owned slice.

This is similar to Box<[T]> (or Arc<[T]>, depending on the Header H type parameter). It holds a heap allocated slice of fixed length. The difference is in internal representation ‒ this is behind a thin pointer and encoded with smaller memory overhead (small slices don't need full 8 bytes of length).

Examples

use squash::OwnedSlice;
let s: OwnedSlice<u16> = OwnedSlice::new(&[1, 2, 3]).unwrap();
assert_eq!(3, s.len());

Internal representation

The heap layout is the header, followed by exactly the number of extra bytes the header needed to encode the length, followed by the actual slice data, with alignments taken into account.

Implementations

impl<T, H> OwnedSlice<T, H> where
    H: Header
[src]

pub fn new(src: &[T]) -> Result<Self, TooLong> where
    T: Clone
[src]

Creates a new owned slice by cloning a content of the passed one.

Errors

If the slice is bigger than the header can encode, this is signalized by the TooLong error. Note that the limits of headers provided by this library are generally quite generous and many users may opt to handle the theoretical errors by unwrapping/panicking.

Trait Implementations

impl<T, H> Clone for OwnedSlice<T, H> where
    H: Header,
    T: Clone
[src]

impl<T, H> Debug for OwnedSlice<T, H> where
    H: Header,
    T: Debug
[src]

impl<T, H> Default for OwnedSlice<T, H> where
    H: Header
[src]

impl<T, H> Deref for OwnedSlice<T, H> where
    H: Header
[src]

type Target = [T]

The resulting type after dereferencing.

impl<T> DerefMut for OwnedSlice<T, BoxHeader>[src]

impl<T, H> Drop for OwnedSlice<T, H> where
    H: Header
[src]

impl<T, H> Send for OwnedSlice<T, H> where
    H: Header + Send + Sync,
    T: Send + Sync
[src]

impl<T, H> Sync for OwnedSlice<T, H> where
    H: Header + Send + Sync,
    T: Send + Sync
[src]

Auto Trait Implementations

impl<T, H> RefUnwindSafe for OwnedSlice<T, H> where
    H: RefUnwindSafe,
    T: RefUnwindSafe
[src]

impl<T, H> Unpin for OwnedSlice<T, H> where
    T: Unpin
[src]

impl<T, H> UnwindSafe for OwnedSlice<T, H> where
    H: RefUnwindSafe,
    T: UnwindSafe
[src]

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.