Struct RcArray

Source
pub struct RcArray<A, R, E, L = ()>
where A: LabelledArray<E, R>, R: RefCounter<L>,
{ /* private fields */ }
Expand description

RcArray is a generic, implementation-agnositc array. It contains logic for enforcing type safety.

The type parameters are, in order:

A: A struct that acts as a reference to an array.
R: A reference-counting structure, that wraps the label. Note that this
   *can be the label itself*. It just needs to have defined ways of incrementing
   and decrementing its reference count.
E: The elements that this array contains.
L: The label that is associated with this array.

Implementations§

Source§

impl<A, R, E, L> RcArray<A, R, E, L>
where A: LabelledArray<E, R>, R: RefCounter<L>,

Source

pub fn ref_count(&self) -> usize

Returns the reference count of the data this RcArray points to.

Source

pub fn to_owned(self) -> Result<A, Self>

Returns an owned version of this array if the caller has exclusive access, or returns back this reference otherwise.

Source

pub fn to_mut(&mut self) -> Option<&mut A>

Returns a mutable reference to the array if the caller has exclusive access, or None otherwise.

Source§

impl<A, R, E, L> RcArray<A, R, E, L>
where A: LabelledArray<E, R> + Clone, R: RefCounter<L>,

Source

pub fn make_owned(self) -> A

Returns an owned version of this array if the caller has exclusive access, or copies the data otherwise.

Source

pub fn make_mut(&mut self) -> &mut A

Returns a mutable reference to the array if the caller has exclusive access, or copies the data otherwise.

Trait Implementations§

Source§

impl<A, R, E, L> ArrayRef for RcArray<A, R, E, L>
where A: LabelledArray<E, R>, R: RefCounter<L>,

Source§

fn clone(ptr: &Self) -> Self

Clones the array reference. Internally just calls its .clone() method.
Source§

impl<A, R, E, L> Clone for RcArray<A, R, E, L>
where A: LabelledArray<E, R>, R: RefCounter<L>,

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<A, R, E, L> Container for RcArray<A, R, E, L>
where A: LabelledArray<E, R>, R: RefCounter<L>,

Source§

fn len(&self) -> usize

Get the size of the container.
Source§

impl<A, R, E, L> CopyMap<usize, E> for RcArray<A, R, E, L>
where A: LabelledArray<E, R>, R: RefCounter<L>,

Source§

fn get(&self, key: usize) -> Option<&E>

Get a reference into this array. Returns None if:

  • The index given is out-of-bounds
Source§

fn get_mut(&mut self, key: usize) -> Option<&mut E>

Get a mutable reference into this array. Returns None if:

  • The array is referenced by another pointer
  • The index given is out-of-bounds
Source§

fn insert(&mut self, key: usize, value: E) -> Option<E>

Insert an element into this array. Returns None if:

  • The array is referenced by another pointer
  • The index given is out-of-bounds
  • There was nothing in the slot previously
Source§

impl<A, R, E, L> Debug for RcArray<A, R, E, L>
where A: LabelledArray<E, R> + SliceArray<E>, R: RefCounter<L>, E: Debug, L: Debug,

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A, R, E, L> DefaultLabelledArray<E, L> for RcArray<A, R, E, L>
where A: DefaultLabelledArray<E, R> + LabelledArray<E, R>, R: RefCounter<L>, E: Default,

Source§

fn with_len(label: L, len: usize) -> Self

Create a new array, initialized to default values.
Source§

impl<A, R, E, L> Drop for RcArray<A, R, E, L>
where A: LabelledArray<E, R>, R: RefCounter<L>,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<A, R, E, L> Index<usize> for RcArray<A, R, E, L>
where A: LabelledArray<E, R> + Index<usize, Output = E>, R: RefCounter<L>,

Source§

type Output = E

The returned type after indexing.
Source§

fn index(&self, idx: usize) -> &E

Performs the indexing (container[index]) operation. Read more
Source§

impl<'b, A, R, E, L> IntoIterator for &'b RcArray<A, R, E, L>
where A: LabelledArray<E, R> + SliceArray<E>, R: RefCounter<L>,

Source§

type Item = &'b E

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'b, E>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<A, R, E, L> LabelledArray<E, L> for RcArray<A, R, E, L>
where A: LabelledArray<E, R>, R: RefCounter<L>,

Source§

fn with_label<F>(label: L, len: usize, func: F) -> Self
where F: FnMut(&mut L, usize) -> E,

Create a new array, with values initialized using a provided function, and label initialized to a provided value.
Source§

fn get_label(&self) -> &L

Get a reference to the label.
Source§

unsafe fn get_unchecked(&self, idx: usize) -> &E

Get a reference to the element at a specified index. Implementations of this method shouldn’t do any safety checks.
Source§

impl<A, R, E> MakeArray<E> for RcArray<A, R, E, ()>
where A: LabelledArray<E, R>, R: RefCounter<()>,

Source§

fn new<F>(len: usize, func: F) -> Self
where F: FnMut(usize) -> E,

Create a new array, with values initialized using a provided function.
Source§

impl<A, R, E, L> SliceArray<E> for RcArray<A, R, E, L>
where A: LabelledArray<E, R> + SliceArray<E>, R: RefCounter<L>,

Source§

fn as_slice(&self) -> &[E]

Returns a reference to a slice into the elements of this array.
Source§

impl<A, R, E, L> Send for RcArray<A, R, E, L>
where A: LabelledArray<E, R> + Send + Sync, R: RefCounter<L> + Send + Sync, E: Send + Sync, L: Send + Sync,

Source§

impl<A, R, E, L> Sync for RcArray<A, R, E, L>
where A: LabelledArray<E, R> + Send + Sync, R: RefCounter<L> + Send + Sync, E: Send + Sync, L: Send + Sync,

Auto Trait Implementations§

§

impl<A, R, E, L> Freeze for RcArray<A, R, E, L>
where A: Freeze,

§

impl<A, R, E, L> RefUnwindSafe for RcArray<A, R, E, L>

§

impl<A, R, E, L> Unpin for RcArray<A, R, E, L>
where A: Unpin, R: Unpin, E: Unpin, L: Unpin,

§

impl<A, R, E, L> UnwindSafe for RcArray<A, R, E, L>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.