pub enum PixelCow<'a, P = ()> {
Borrowed(PixelSlice<'a, P>),
Owned(PixelBuffer<P>),
}Expand description
Borrowed-or-owned pixels with the same metadata and stride-aware view.
This is the pixel-buffer analogue of alloc::borrow::Cow: operations
can return a borrowed PixelSlice on their fast path and an owned
PixelBuffer only when conversion or mutation requires allocation.
Variants§
Borrowed(PixelSlice<'a, P>)
Pixels borrowed from the caller.
Owned(PixelBuffer<P>)
Independently owned pixels.
Implementations§
Source§impl<P> PixelCow<'_, P>
impl<P> PixelCow<'_, P>
Sourcepub const fn is_borrowed(&self) -> bool
pub const fn is_borrowed(&self) -> bool
Whether this value still borrows its pixel storage.
Sourcepub fn as_slice(&self) -> PixelSlice<'_, P>
pub fn as_slice(&self) -> PixelSlice<'_, P>
Borrow either representation as a uniform pixel slice.
Source§impl<'a> PixelCow<'a>
impl<'a> PixelCow<'a>
Sourcepub fn to_mut(&mut self) -> &mut PixelBuffer
pub fn to_mut(&mut self) -> &mut PixelBuffer
Obtain mutable owned pixels, cloning the borrowed pixels if needed.
Sourcepub fn into_owned(self) -> PixelBuffer
pub fn into_owned(self) -> PixelBuffer
Consume this value, cloning the pixels only when they are borrowed.
Trait Implementations§
Source§impl<'a, P> From<PixelBuffer<P>> for PixelCow<'a, P>
impl<'a, P> From<PixelBuffer<P>> for PixelCow<'a, P>
Source§fn from(value: PixelBuffer<P>) -> PixelCow<'a, P>
fn from(value: PixelBuffer<P>) -> PixelCow<'a, P>
Converts to this type from the input type.
Source§impl<'a, P> From<PixelSlice<'a, P>> for PixelCow<'a, P>
impl<'a, P> From<PixelSlice<'a, P>> for PixelCow<'a, P>
Source§fn from(value: PixelSlice<'a, P>) -> PixelCow<'a, P>
fn from(value: PixelSlice<'a, P>) -> PixelCow<'a, P>
Converts to this type from the input type.
Auto Trait Implementations§
impl<'a, P> Freeze for PixelCow<'a, P>
impl<'a, P> RefUnwindSafe for PixelCow<'a, P>where
P: RefUnwindSafe,
impl<'a, P> Send for PixelCow<'a, P>where
P: Send,
impl<'a, P> Sync for PixelCow<'a, P>where
P: Sync,
impl<'a, P> Unpin for PixelCow<'a, P>where
P: Unpin,
impl<'a, P> UnsafeUnpin for PixelCow<'a, P>
impl<'a, P> UnwindSafe for PixelCow<'a, P>where
P: UnwindSafe,
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