Skip to main content

EncodeError

Enum EncodeError 

Source
#[non_exhaustive]
pub enum EncodeError { StreamPositionOverflow { position: u64, input_bytes: u64, }, OutputTooSmall { provided: usize, }, AllocationFailed { requested: usize, }, Bound(SizeOverflow), DictionaryUnsupportedForQuality { quality: Quality, }, UnsupportedStreamOffset { offset: u64, }, AbandonedSession, InvalidState { attempted: &'static str, }, InternalInvariant { detail: &'static str, }, }
Expand description

Error returned by an encoding operation.

Every variant describes something about the operation: the destination was too small, the dictionary cannot be used at this quality, an allocation was refused. A configuration that could never work is rejected earlier, by Compressor::new, and never reaches here.

§Examples

use mbrotli::{Compressor, EncodeError, EncoderConfig, Quality};

let mut encoder = Compressor::new(EncoderConfig::default().with_quality(Quality::Q1))?;
let mut cramped = [0u8; 1];

assert!(matches!(
    encoder.compress_to_slice(b"a payload that will not fit in one byte", &mut cramped),
    Err(EncodeError::OutputTooSmall { provided: 1 })
));

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.
§

StreamPositionOverflow

Logical placement plus input exceeds the RFC’s 63-bit position range.

Fields

§position: u64

Position before accepting this input.

§input_bytes: u64

Number of input bytes offered.

§

OutputTooSmall

The caller’s destination cannot hold the whole stream.

Size one with Compressor::max_compressed_size to make this impossible.

Fields

§provided: usize

How many bytes the caller offered.

§

AllocationFailed

An allocation the operation needed was refused.

Fields

§requested: usize

How many bytes were asked for.

§

Bound(SizeOverflow)

The compressed-size bound does not fit in a usize.

§

DictionaryUnsupportedForQuality

This quality cannot compress against an attached dictionary.

The reference compiles its compound-dictionary search only for the match finders qualities five and above select, and silently ignores the dictionary elsewhere. This crate refuses instead: a stream compressed without the dictionary it was given decodes perfectly well, so the mistake would stay invisible until a decoder that does attach it produced the wrong bytes.

Fields

§quality: Quality

The quality that was asked for.

§

UnsupportedStreamOffset

A non-zero stream offset was asked for on an unsupported path.

Continuations require experimental and quality two or above.

Fields

§offset: u64

The offset that was asked for.

§

AbandonedSession

A session was abandoned without being dropped, and its state is unknown.

::core::mem::forget can skip a session’s destructor, which is the one way a compressor can be left holding state no operation has cleaned up. Rather than trusting it, the compressor refuses until Compressor::recover has put it back into a known state.

§

InvalidState

An operation was asked for that the session’s state does not allow.

Fields

§attempted: &'static str

What was attempted.

§

InternalInvariant

An invariant inside the encoder was violated.

No valid caller input can cause this; it is a defect in this crate.

Fields

§detail: &'static str

What the encoder reported.

Trait Implementations§

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, __formatter: &mut Formatter<'_>) -> Result

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

impl Error for EncodeError

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

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 From<EncodeError> for Error

Available on non-crate feature no_std only.
Source§

fn from(value: EncodeError) -> Self

Carries an encoding failure through a std::io adapter.

A short destination becomes std::io::ErrorKind::WriteZero and an allocation failure std::io::ErrorKind::OutOfMemory, so a caller can tell the two apart without downcasting; everything else keeps the original error as its source.

Source§

impl From<SizeOverflow> for EncodeError

Source§

fn from(source: SizeOverflow) -> Self

Converts to this type from the input type.

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> 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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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.