Skip to main content

DecodeError

Enum DecodeError 

Source
#[non_exhaustive]
pub enum DecodeError {
Show 14 variants OutOfMemory, InvalidParam, BitstreamError, UnsupportedFeature, Suspended, UserAbort, NotEnoughData, FrameFailed, InvalidCrop { left: u32, top: u32, width: u32, height: u32, }, InvalidScale { width: u32, height: u32, }, InvalidStride { plane: Plane, stride: usize, }, BufferTooShort { plane: Plane, len: usize, needed: usize, }, OutputMismatch { mode: ColorMode, }, InvalidParameter { name: &'static str, },
}
Expand description

Why a decoding or one of its inputs failed.

The variants up to DecodeError::NotEnoughData are libwebp’s VP8StatusCode values 1 to 7; DecodeError::code returns the C code. DecodeError::FrameFailed is a failed animation frame, for which libwebp reports no status. The others are the API’s own validation, which runs before the translation is called.

§Examples

use webp::api::decode::{ColorMode, Config, DecodeError};

let error = Config::new(ColorMode::Rgb).crop(1, 0, 8, 8).validate().unwrap_err();
assert_eq!(error, DecodeError::InvalidCrop { left: 1, top: 0, width: 8, height: 8 });
assert_eq!(error.code(), None);
assert_eq!(DecodeError::BitstreamError.to_string(), "invalid bitstream");

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

OutOfMemory

Memory could not be allocated (C: VP8_STATUS_OUT_OF_MEMORY).

§

InvalidParam

libwebp refused a parameter (C: VP8_STATUS_INVALID_PARAM): for the incremental decoder, a caller output that does not fit the image, or a crop outside it, which it learns from the header; mixed calls of IncrementalDecoder::append and IncrementalDecoder::update, or a shorter buffer passed to update.

§

BitstreamError

The bitstream is invalid or truncated (C: VP8_STATUS_BITSTREAM_ERROR).

§

UnsupportedFeature

The bitstream uses a feature that this decoder does not support, such as an animation given to decode (C: VP8_STATUS_UNSUPPORTED_FEATURE).

§

Suspended

The incremental decoding has not completed: the error of IncrementalDecoder::into_image before that (C: VP8_STATUS_SUSPENDED, which the decoding steps report as Status::NeedsMoreData).

§

UserAbort

The decoding was aborted by an I/O hook (C: VP8_STATUS_USER_ABORT); the API sets no hooks, so it does not return this code.

§

NotEnoughData

The data ends before the information asked for (C: VP8_STATUS_NOT_ENOUGH_DATA): read more and try again.

§

FrameFailed

The animation decoder failed on a frame; libwebp’s WebPAnimDecoderGetNext reports no status.

§

InvalidCrop

The crop has a zero size, an odd left or top, a value above i32::MAX, or does not lie inside the image.

Fields

§left: u32

The left edge given.

§top: u32

The top edge given.

§width: u32

The width given.

§height: u32

The height given.

§

InvalidScale

A scaled width or height is 0 or above 16383.

Fields

§width: u32

The width given.

§height: u32

The height given.

§

InvalidStride

A stride is 0, shorter than a row of the output, longer than i32::MAX, or so long that the plane’s extent does not fit in usize.

Fields

§plane: Plane

The output with the stride.

§stride: usize

The stride given, in bytes.

§

BufferTooShort

A buffer is shorter than its rows: (rows - 1) * stride + row length bytes, or empty.

Fields

§plane: Plane

The output that is too short.

§len: usize

Its length, in bytes.

§needed: usize

The bytes that its rows and stride address.

§

OutputMismatch

The output does not match the color mode: Output::Rows for a YUV mode, Output::Planes for an RGB mode, an alpha plane missing for ColorMode::Yuva or given for ColorMode::Yuv, or caller memory asked to become an Image.

Fields

§mode: ColorMode

The color mode of the configuration.

§

InvalidParameter

A parameter is outside the range the API accepts: dithering or alpha_dithering above 100.

Fields

§name: &'static str

The parameter’s name.

Implementations§

Source§

impl DecodeError

Source

pub const fn code(&self) -> Option<VP8StatusCode>

The VP8StatusCode of this error, or None for DecodeError::FrameFailed and the API’s own validation errors.

§Examples
use webp::api::decode::DecodeError;
use webp::webp::decode::VP8StatusCode;

assert_eq!(DecodeError::NotEnoughData.code(), Some(VP8StatusCode::VP8_STATUS_NOT_ENOUGH_DATA));
assert_eq!(DecodeError::FrameFailed.code(), None);

Trait Implementations§

Source§

impl Clone for DecodeError

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DecodeError

Source§

impl Debug for DecodeError

Source§

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

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

impl Display for DecodeError

Source§

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

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

impl Eq for DecodeError

Source§

impl Error for DecodeError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Replaced by Error::source.
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl Hash for DecodeError

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DecodeError

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DecodeError

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.