#[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
StreamPositionOverflow
Logical placement plus input exceeds the RFC’s 63-bit position range.
Fields
OutputTooSmall
The caller’s destination cannot hold the whole stream.
Size one with Compressor::max_compressed_size to make this
impossible.
AllocationFailed
An allocation the operation needed was refused.
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.
UnsupportedStreamOffset
A non-zero stream offset was asked for on an unsupported path.
Continuations require experimental and quality two or above.
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.
InternalInvariant
An invariant inside the encoder was violated.
No valid caller input can cause this; it is a defect in this crate.
Trait Implementations§
Source§impl Debug for EncodeError
impl Debug for EncodeError
Source§impl Display for EncodeError
impl Display for EncodeError
Source§impl Error for EncodeError
impl Error for EncodeError
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()
Source§impl From<EncodeError> for Error
Available on non-crate feature no_std only.
impl From<EncodeError> for Error
no_std only.Source§fn from(value: EncodeError) -> Self
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.