Skip to main content

EncodeError

Enum EncodeError 

Source
#[non_exhaustive]
pub enum EncodeError {
Show 15 variants OutOfMemory, BitstreamOutOfMemory, NullParameter, InvalidConfiguration, BadDimension, Partition0Overflow, PartitionOverflow, BadWrite, FileTooBig, UserAbort, Unreported, InvalidDimensions { width: u32, height: u32, }, InvalidStride { plane: Plane, stride: usize, }, BufferTooShort { plane: Plane, len: usize, needed: usize, }, InvalidParameter { name: &'static str, },
}
Expand description

Why an encoding or one of its inputs failed.

The variants up to EncodeError::Unreported are the codes that libwebp records in WebPPicture::error_code, with C’s rule that the first recorded error is kept; EncodeError::code returns the C code. The others are the API’s own validation, which runs before the translation is called.

§Examples

use webp::api::encode::{Config, EncodeError};

let error = Config::new().quality(f32::NAN).validate().unwrap_err();
assert_eq!(error, EncodeError::InvalidParameter { name: "quality" });
assert_eq!(error.code(), None);
assert_eq!(error.to_string(), "invalid parameter: quality");

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 for the picture or the encoder could not be allocated (C: VP8_ENC_ERROR_OUT_OF_MEMORY).

§

BitstreamOutOfMemory

Memory for the bitstream could not be allocated (C: VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY).

§

NullParameter

A required plane is missing (C: VP8_ENC_ERROR_NULL_PARAMETER); the picture of an encoding whose callback panicked has no planes.

§

InvalidConfiguration

The configuration fails libwebp’s validation, or the encoder rejects a combination (C: VP8_ENC_ERROR_INVALID_CONFIGURATION).

§

BadDimension

The picture’s dimensions are rejected (C: VP8_ENC_ERROR_BAD_DIMENSION).

§

Partition0Overflow

The first partition exceeds 512 KiB (C: VP8_ENC_ERROR_PARTITION0_OVERFLOW); a lower quality or more segments help.

§

PartitionOverflow

A token partition exceeds 16 MiB (C: VP8_ENC_ERROR_PARTITION_OVERFLOW).

§

BadWrite

The writer returned false, or the memory writer could not grow (C: VP8_ENC_ERROR_BAD_WRITE).

§

FileTooBig

The file would exceed 4 GiB (C: VP8_ENC_ERROR_FILE_TOO_BIG).

§

UserAbort

The progress hook returned false (C: VP8_ENC_ERROR_USER_ABORT).

§

Unreported

The encoder failed without recording a code (C returns 0 with VP8_ENC_OK; libwebp does so when QuantizeLevels runs out of memory).

§

InvalidDimensions

The width or height is 0 or above 16383 (WEBP_MAX_DIMENSION).

Fields

§width: u32

The width given.

§height: u32

The height given.

§

InvalidStride

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

Fields

§plane: Plane

The input with the stride.

§stride: usize

The stride given, in elements of the input’s type.

§

BufferTooShort

A buffer is shorter than its rows: (rows - 1) * stride + row length elements.

Fields

§plane: Plane

The input that is too short.

§len: usize

Its length, in elements.

§needed: usize

The elements that its dimensions and stride address.

§

InvalidParameter

A parameter is outside the range the API accepts: quality (finite, 0 to 100), target_psnr (finite) or lossless_level (0 to 9).

Fields

§name: &'static str

The parameter’s name.

Implementations§

Source§

impl EncodeError

Source

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

The WebPEncodingError that libwebp recorded for this error, or None for an error of the API’s own validation. EncodeError::Unreported returns VP8_ENC_OK, the code C leaves in that case.

§Examples
use webp::api::encode::EncodeError;
use webp::webp::encode::WebPEncodingError;

assert_eq!(EncodeError::UserAbort.code(), Some(WebPEncodingError::VP8_ENC_ERROR_USER_ABORT));
assert_eq!(EncodeError::InvalidDimensions { width: 0, height: 1 }.code(), None);

Trait Implementations§

Source§

impl Clone for EncodeError

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 EncodeError

Source§

impl Debug for EncodeError

Source§

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

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

impl Display for EncodeError

Source§

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

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

impl Eq for EncodeError

Source§

impl Error for EncodeError

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 EncodeError

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 EncodeError

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 EncodeError

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.