Struct shared_slice::rc::RcSlice [-]  [+] [src]

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

A reference-counted slice type.

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

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

Examples

use shared_slice::rc::RcSlice;

let x = RcSlice::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::rc::RcSlice;

let n = 5;

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

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

Methods

impl<T> RcSlice<T>

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

Construct a new RcSlice 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) -> RcSlice<T>

Construct a new RcSlice 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) -> RcSlice<T>

Construct a new RcSlice 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) -> RcSlice<T>

Construct a new RcSlice 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> Clone for RcSlice<T>

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

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

impl<T> Deref for RcSlice<T>

type Target = [T]

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

impl<T: PartialEq> PartialEq for RcSlice<T>

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

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

impl<T: Eq> Eq for RcSlice<T>

fn assert_receiver_is_total_eq(&self)

impl<T: PartialOrd> PartialOrd for RcSlice<T>

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

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

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

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

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

impl<T: Ord> Ord for RcSlice<T>

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

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

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

impl<T: Debug> Debug for RcSlice<T>

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

impl<T> Drop for RcSlice<T>

fn drop(&mut self)