[][src]Struct canvas::CanvasReuseError

pub struct CanvasReuseError<P: AsBytes + FromBytes> { /* fields omitted */ }

Error representation for a failed buffer reuse for a canvas.

Emitted as a result of Canvas::from_rec 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_rec. 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 rec = Rec::<u8>::new(16);
let allocation = rec.as_bytes().as_ptr();

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

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

Methods

impl<P: AsBytes + FromBytes> CanvasReuseError<P>[src]

pub fn into_rec(self) -> Rec<P>[src]

Unwrap the original buffer.

Trait Implementations

impl<P: AsBytes + FromBytes> Debug for CanvasReuseError<P>[src]

impl<P: Eq + AsBytes + FromBytes> Eq for CanvasReuseError<P>[src]

impl<P: PartialEq + AsBytes + FromBytes> PartialEq<CanvasReuseError<P>> for CanvasReuseError<P>[src]

impl<P: AsBytes + FromBytes> StructuralEq for CanvasReuseError<P>[src]

impl<P: AsBytes + FromBytes> StructuralPartialEq for CanvasReuseError<P>[src]

Auto Trait Implementations

impl<P> RefUnwindSafe for CanvasReuseError<P> where
    P: RefUnwindSafe

impl<P> Send for CanvasReuseError<P> where
    P: Send

impl<P> Sync for CanvasReuseError<P> where
    P: Sync

impl<P> Unpin for CanvasReuseError<P> where
    P: Unpin

impl<P> UnwindSafe for CanvasReuseError<P> where
    P: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.