Struct shared_slice::arc::ArcSlice [-]  [+] [src]

pub struct ArcSlice<T> {
    // some fields omitted
}

A reference-counted slice type.

This is exactly like &[T] except without lifetimes, so the allocation only disappears once all ArcSlices have disappeared.

NB. this can lead to applications effectively leaking memory if a short subslice of a long ArcSlice is held.

Examples

use shared_slice::arc::ArcSlice;

let x = ArcSlice::new(Box::new(["foo", "bar", "baz"]));
println!("{:?}", x); // ["foo", "bar", "baz"]
println!("{:?}", x.slice(1, 3)); // ["bar", "baz"]

Constructing with a dynamic number of elements:

use shared_slice::arc::ArcSlice;

let n = 5;

let v: Vec<u8> = (0u8..n).collect(); // 0, ..., 4

let x = ArcSlice::new(v.into_boxed_slice());
assert_eq!(&*x, [0, 1, 2, 3, 4]);

Methods

impl<T> ArcSlice<T>

fn new(slice: Box<[T]>) -> ArcSlice<T>

Construct a new ArcSlice containing the elements of slice.

This reuses the allocation of slice.

fn downgrade(&self) -> WeakSlice<T>

Downgrade self into a weak slice.

fn slice(self, lo: usize, hi: usize) -> ArcSlice<T>

Construct a new ArcSlice that only points to elements at indices lo (inclusive) through hi (exclusive).

This consumes self to avoid unnecessary reference-count modifications. Use .clone() if it is necessary to refer to self after calling this.

Panics

Panics if lo > hi or if either are strictly greater than self.len().

fn slice_to(self, hi: usize) -> ArcSlice<T>

Construct a new ArcSlice that only points to elements at indices up to hi (exclusive).

This consumes self to avoid unnecessary reference-count modifications. Use .clone() if it is necessary to refer to self after calling this.

Panics

Panics if hi > self.len().

fn slice_from(self, lo: usize) -> ArcSlice<T>

Construct a new ArcSlice that only points to elements at indices starting at lo (inclusive).

This consumes self to avoid unnecessary reference-count modifications. Use .clone() if it is necessary to refer to self after calling this.

Panics

Panics if lo > self.len().

Trait Implementations

impl<T: Send + Sync> Send for ArcSlice<T>

impl<T: Send + Sync> Sync for ArcSlice<T>

impl<T> Clone for ArcSlice<T>

fn clone(&self) -> ArcSlice<T>

fn clone_from(&mut self, source: &Self)

impl<T> Deref for ArcSlice<T>

type Target = [T]

fn deref<'a>(&'a self) -> &'a [T]

impl<T: PartialEq> PartialEq for ArcSlice<T>

fn eq(&self, other: &ArcSlice<T>) -> bool

fn ne(&self, other: &ArcSlice<T>) -> bool

impl<T: Eq> Eq for ArcSlice<T>

fn assert_receiver_is_total_eq(&self)

impl<T: PartialOrd> PartialOrd for ArcSlice<T>

fn partial_cmp(&self, other: &ArcSlice<T>) -> Option<Ordering>

fn lt(&self, other: &ArcSlice<T>) -> bool

fn le(&self, other: &ArcSlice<T>) -> bool

fn gt(&self, other: &ArcSlice<T>) -> bool

fn ge(&self, other: &ArcSlice<T>) -> bool

impl<T: Ord> Ord for ArcSlice<T>

fn cmp(&self, other: &ArcSlice<T>) -> Ordering

impl<S: Hasher + Writer, T: Hash<S>> Hash<S> for ArcSlice<T>

fn hash(&self, state: &mut S)

impl<T: Debug> Debug for ArcSlice<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T> Drop for ArcSlice<T>

fn drop(&mut self)