#[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
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).
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
BufferTooShort
A buffer is shorter than its rows: (rows - 1) * stride + row length
elements.
Fields
InvalidParameter
A parameter is outside the range the API accepts: quality (finite,
0 to 100), target_psnr (finite) or lossless_level (0 to 9).
Implementations§
Source§impl EncodeError
impl EncodeError
Sourcepub const fn code(&self) -> Option<WebPEncodingError>
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
impl Clone for EncodeError
impl Copy for EncodeError
Source§impl Debug for EncodeError
impl Debug for EncodeError
Source§impl Display for EncodeError
impl Display for EncodeError
impl Eq for EncodeError
Source§impl Error for EncodeError
impl Error for EncodeError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()