pub struct RcArray<T> { /* private fields */ }
Expand description
A reference-counted pointer to an array.
It allow access to the elements of the array with one indirection, allow the array to grow
until the specified capacity and has a function RcArray::make_mut
.
It is different from Rc<Vec>
and Rc<[T]>
. In Rc<Vec>
it is necessary to follow two
indirection to access an element. In Rc<[T]>
the array cannot grow and the function
Rc::make_mut
is not applicable.
TODO: write about mem::size_of
.
Examples
use fera_array::{Array, RcArray};
let a = RcArray::with_value(0, 5);
// a and b share the inner data, this is a O(1) operation
let mut b = a.clone();
// the inner data in cloned (copy on write)
b[1] = 1;
assert_eq!(0, a[1]);
assert_eq!(1, b[1]);
// the inner data is not shared, so it can be modified without being cloned
b[2] = 2;
Implementations§
Trait Implementations§
source§impl<T> Array<T> for RcArray<T>where
T: Clone,
impl<T> Array<T> for RcArray<T>where
T: Clone,
source§fn with_value(value: T, n: usize) -> RcArray<T>where
T: Clone,
fn with_value(value: T, n: usize) -> RcArray<T>where
T: Clone,
Creates a new array with
n
repeated value
.source§fn get(&self, index: usize) -> Option<&T>
fn get(&self, index: usize) -> Option<&T>
Returns a reference to the element of the array at
index
, or None
if the index is out
of bounds. Read moresource§fn get_mut(&mut self, index: usize) -> Option<&mut T>
fn get_mut(&mut self, index: usize) -> Option<&mut T>
Returns a mutable reference to the element of the array at
index
, or None
if the index
is out of bounds. Read moresource§unsafe fn get_unchecked(&self, index: usize) -> &T
unsafe fn get_unchecked(&self, index: usize) -> &T
Returns a reference to the element of the array at
index
, without doing bounds checking.source§impl<T> DynamicArray<T> for RcArray<T>where
T: Clone,
impl<T> DynamicArray<T> for RcArray<T>where
T: Clone,
source§fn with_capacity(cap: usize) -> RcArray<T>
fn with_capacity(cap: usize) -> RcArray<T>
Creates a array with the specified capacity. Read more
source§fn reserve(&mut self, additional: usize)
fn reserve(&mut self, additional: usize)
Reserve capacity for at least
additional
more elements. Read moresource§unsafe fn push_unchecked(&mut self, value: T)
unsafe fn push_unchecked(&mut self, value: T)
Write value to the end of the array and increment the length. Read more
source§fn extend<I>(&mut self, iter: I)where
Self: Sized,
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
Self: Sized,
I: IntoIterator<Item = T>,
Appends all elements of
iter
to the array. Read moresource§impl<T> FromIterator<T> for RcArray<T>
impl<T> FromIterator<T> for RcArray<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for RcArray<T>
impl<T> !Send for RcArray<T>
impl<T> !Sync for RcArray<T>
impl<T> Unpin for RcArray<T>
impl<T> !UnwindSafe for RcArray<T>
Blanket Implementations§
source§impl<P, Idx> PropIndexMut<Idx> for Pwhere
P: IndexMut<Idx>,
impl<P, Idx> PropIndexMut<Idx> for Pwhere
P: IndexMut<Idx>,
source§fn set_values_from<P, I>(&mut self, iter: I, source: &P)where
I: IntoIterator,
<I as IntoIterator>::Item: IntoOwned<Idx>,
Idx: Clone,
P: Index<Idx, Output = Self::Output>,
Self::Output: Clone,
fn set_values_from<P, I>(&mut self, iter: I, source: &P)where
I: IntoIterator,
<I as IntoIterator>::Item: IntoOwned<Idx>,
Idx: Clone,
P: Index<Idx, Output = Self::Output>,
Self::Output: Clone,
Set the value associated with each key produced by
iter
to the value associated with the
key in the property source
. Read moresource§fn set_values<I>(&mut self, iter: I, value: Self::Output)where
I: IntoIterator,
<I as IntoIterator>::Item: IntoOwned<Idx>,
Self::Output: Clone,
fn set_values<I>(&mut self, iter: I, value: Self::Output)where
I: IntoIterator,
<I as IntoIterator>::Item: IntoOwned<Idx>,
Self::Output: Clone,
Set the value associated with keys produced by
iter
to value
.