Skip to main content

PixelCow

Enum PixelCow 

Source
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>

Source

pub const fn is_borrowed(&self) -> bool

Whether this value still borrows its pixel storage.

Source

pub const fn is_owned(&self) -> bool

Whether this value owns its pixel storage.

Source

pub fn as_slice(&self) -> PixelSlice<'_, P>

Borrow either representation as a uniform pixel slice.

Source§

impl<'a> PixelCow<'a>

Source

pub fn to_mut(&mut self) -> &mut PixelBuffer

Obtain mutable owned pixels, cloning the borrowed pixels if needed.

Source

pub fn into_owned(self) -> PixelBuffer

Consume this value, cloning the pixels only when they are borrowed.

Trait Implementations§

Source§

impl<P> Debug for PixelCow<'_, P>

Source§

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

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

impl<'a, P> From<PixelBuffer<P>> for PixelCow<'a, P>

Source§

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>

Source§

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> 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> 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, 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.