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

Unwrap the original buffer.

Trait Implementations

Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.