Struct fera_array::RcArray

source ·
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

Returns a slice containing the entire array.

Returns a mutable slice containing the entire array.

Makes the array mutable. The inner data is cloned if there is more than one reference to it, otherwise the array is already mutable.

Trait Implementations

Creates a new array with n repeated value.
Returns the number of elements in the array.
Returns a reference to the element of the array at index, or None if the index is out of bounds. Read more
Returns a mutable reference to the element of the array at index, or None if the index is out of bounds. Read more
Returns a reference to the element of the array at index, without doing bounds checking.
Returns a mutable reference to the element of the array at index, without doing bounds checking. Read more
Returns true if the length of the array is 0, otherwise false.
Returns a iterator over the array.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Executes the destructor for this type. Read more
Creates a array with the specified capacity. Read more
Change the length of the array.
Returns the capacity of the array.
Reserve capacity for at least additional more elements. Read more
Write value to the end of the array and increment the length. Read more
Appends the value to the array. Read more
Appends all elements of iter to the array. Read more
Appends all elements in a slice to the array. Read more
Extend the array by n additional clones of value. Read more
Creates a value from an iterator. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.