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>
impl<'a, T: Element, D: Dimension> CowArray<'a, T, D>
Sourcepub fn from_owned(arr: Array<T, D>) -> Self
pub fn from_owned(arr: Array<T, D>) -> Self
Create a CowArray from an owned array.
Sourcepub fn layout(&self) -> MemoryLayout
pub fn layout(&self) -> MemoryLayout
Memory layout.
Sourcepub fn is_borrowed(&self) -> bool
pub fn is_borrowed(&self) -> bool
Whether this is a borrowed (view) variant.
Sourcepub fn into_owned(self) -> Array<T, D>
pub fn into_owned(self) -> Array<T, D>
Convert to an owned array, cloning if currently borrowed.
Sourcepub fn to_mut(&mut self) -> &mut Array<T, D>
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.
Sourcepub fn view(&self) -> ArrayView<'_, T, D>
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.
Sourcepub fn flags(&self) -> ArrayFlags
pub fn flags(&self) -> ArrayFlags
Array flags.
Trait Implementations§
Auto Trait Implementations§
impl<'a, T, D> Freeze for CowArray<'a, T, D>
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>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more