Struct MatrixReuseError

Source
pub struct MatrixReuseError<P> { /* private fields */ }
Expand description

Error representation for a failed buffer reuse for an image.

Emitted as a result of Matrix::from_buffer when the buffer capacity is not large enough to serve as an image of requested layout with causing a reallocation.

It is possible to retrieve the buffer that cause the failure with into_buffer. This allows one to manually try to correct the error with additional checks, or implement a fallback strategy which does not require the interpretation as a full image.

let buffer = TexelBuffer::<u8>::new(16);
let allocation = buffer.as_bytes().as_ptr();

let bad_layout = layout::Matrix::width_and_height(buffer.capacity() + 1, 1).unwrap();
let error = match Matrix::from_reused_buffer(buffer, bad_layout) {
    Ok(_) => unreachable!("The layout requires one too many pixels"),
    Err(error) => error,
};

// Get back the original buffer.
let buffer = error.into_buffer();
assert_eq!(buffer.as_bytes().as_ptr(), allocation);

Implementations§

Source§

impl<P> MatrixReuseError<P>

Source

pub fn into_buffer(self) -> TexelBuffer<P>

Unwrap the original buffer.

Trait Implementations§

Source§

impl<P> Debug for MatrixReuseError<P>

Source§

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

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

impl<P: PartialEq> PartialEq for MatrixReuseError<P>

Source§

fn eq(&self, other: &MatrixReuseError<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: Eq> Eq for MatrixReuseError<P>

Source§

impl<P> StructuralPartialEq for MatrixReuseError<P>

Auto Trait Implementations§

§

impl<P> Freeze for MatrixReuseError<P>

§

impl<P> RefUnwindSafe for MatrixReuseError<P>
where P: RefUnwindSafe,

§

impl<P> Send for MatrixReuseError<P>
where P: Send,

§

impl<P> Sync for MatrixReuseError<P>
where P: Sync,

§

impl<P> Unpin for MatrixReuseError<P>
where P: Unpin,

§

impl<P> UnwindSafe for MatrixReuseError<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<P, L> PlaneOf<&L> for P
where P: PlaneOf<L>,

Source§

type Plane = <P as PlaneOf<L>>::Plane

Source§

fn get_plane(self, layout: &&L) -> Option<<P as PlaneOf<&L>>::Plane>

Get the layout describing the plane.
Source§

impl<P, L> PlaneOf<&mut L> for P
where P: PlaneOf<L>,

Source§

type Plane = <P as PlaneOf<L>>::Plane

Source§

fn get_plane(self, layout: &&mut L) -> Option<<P as PlaneOf<&mut L>>::Plane>

Get the layout describing the plane.
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.