Skip to main content

CowArray

Enum CowArray 

Source
pub enum CowArray<'a, T: Element, D: Dimension> {
    Borrowed(ArrayView<'a, T, D>),
    Owned(Array<T, D>),
}
Expand description

A copy-on-write array that is either a borrowed view or an owned array.

This is useful when a function might or might not need to allocate: it can accept borrowed data and only clone if mutation is required.

Variants§

§

Borrowed(ArrayView<'a, T, D>)

Borrowed — refers to data owned by another array.

§

Owned(Array<T, D>)

Owned — has its own data buffer.

Implementations§

Source§

impl<'a, T: Element, D: Dimension> CowArray<'a, T, D>

Source

pub fn from_view(view: ArrayView<'a, T, D>) -> Self

Create a CowArray from a borrowed view.

Source

pub fn from_owned(arr: Array<T, D>) -> Self

Create a CowArray from an owned array.

Source

pub fn shape(&self) -> &[usize]

Shape as a slice.

Source

pub fn ndim(&self) -> usize

Number of dimensions.

Source

pub fn size(&self) -> usize

Total number of elements.

Source

pub fn is_empty(&self) -> bool

Whether the array has zero elements.

Source

pub fn layout(&self) -> MemoryLayout

Memory layout.

Source

pub fn is_borrowed(&self) -> bool

Whether this is a borrowed (view) variant.

Source

pub fn is_owned(&self) -> bool

Whether this is an owned variant.

Source

pub fn into_owned(self) -> Array<T, D>

Convert to an owned array, cloning if currently borrowed.

Source

pub fn to_mut(&mut self) -> &mut Array<T, D>

Ensure this is the owned variant, cloning if necessary, and return a mutable reference to the owned array.

Source

pub fn view(&self) -> ArrayView<'_, T, D>

Get a read-only view of the data.

If this is a borrowed variant, returns a view with the same lifetime as &self. If owned, returns a view borrowing from self.

Source

pub fn as_ptr(&self) -> *const T

Raw pointer to the first element.

Source

pub fn flags(&self) -> ArrayFlags

Array flags.

Trait Implementations§

Source§

impl<T: Element, D: Dimension> Clone for CowArray<'_, T, D>

Source§

fn clone(&self) -> Self

Returns a duplicate 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<T: Element, D: Dimension> Debug for CowArray<'_, T, D>

Source§

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

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

impl<T: Element, D: Dimension> Display for CowArray<'_, T, D>

Source§

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

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

impl<T: Element, D: Dimension> From<Array<T, D>> for CowArray<'_, T, D>

Source§

fn from(arr: Array<T, D>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Element, D: Dimension> From<ArrayView<'a, T, D>> for CowArray<'a, T, D>

Source§

fn from(view: ArrayView<'a, T, D>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a, T, D> Freeze for CowArray<'a, T, D>
where D: Freeze, <D as Dimension>::NdarrayDim: Freeze,

§

impl<'a, T, D> RefUnwindSafe for CowArray<'a, T, D>

§

impl<'a, T, D> Send for CowArray<'a, T, D>

§

impl<'a, T, D> Sync for CowArray<'a, T, D>

§

impl<'a, T, D> Unpin for CowArray<'a, T, D>
where D: Unpin, <D as Dimension>::NdarrayDim: Unpin,

§

impl<'a, T, D> UnsafeUnpin for CowArray<'a, T, D>

§

impl<'a, T, D> UnwindSafe for CowArray<'a, T, D>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.