#[non_exhaustive]pub enum Error {
Truncated,
Incomplete {
deficit: Sensitive<NonZeroUsize>,
},
ExtraneousBytes,
BadLengthValue,
BadMessage(&'static str),
InvalidMessage(Cow<'static, str>),
MissingData,
Bug(Bug),
}
Expand description
Error type for decoding Tor objects from bytes.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Truncated
Something was truncated
It might be an inner data structure, or the outer message being parsed.
Incomplete
Tried to read something, but we didn’t find enough bytes.
This can means that the outer object is truncated. Possibly we need to read more and try again,
This error is only returned by Reader
s created with
from_possibly_incomplete_slice
.
§Do not directly construct this variant
It is usually a bug to explicitly construct this variant.
Use Reader::incomplete_error
instead.
In tests using
Reader::from_slice_for_test
,
use Error::new_incomplete_for_test
.
Fields
deficit: Sensitive<NonZeroUsize>
Lower bound on number of additional bytes needed
ExtraneousBytes
Called Reader::should_be_exhausted(), but found bytes anyway.
BadLengthValue
Invalid length value
BadMessage(&'static str)
An attempt to parse an object failed for some reason related to its contents.
InvalidMessage(Cow<'static, str>)
An attempt to parse an object failed for some reason related to its contents.
§General case, more specific variants also exist
This variant is used when encountering parsing trouble for which there is no more specific variant.
Other variants can occur when deserialising malformed messages.
for example (but not necessarily only):
ExtraneousBytes
,
MissingData
, and
BadLengthValue
.
MissingData
The message contains data which is too short (perhaps in an inner counted section)
§Usually, do not directly construct this variant
It is often a bug to explicitly construct this variant.
Consider Reader::incomplete_error
instead.
(It can be appropriate in test cases, or during bespoke parsing of an inner substructure.)
Bug(Bug)
A parsing error that should never happen.
We use this one in lieu of calling assert() and expect() and unwrap() from within parsing code.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new_incomplete_for_test(deficit: usize) -> Self
pub fn new_incomplete_for_test(deficit: usize) -> Self
Make an Error::Incomplete
with a specified deficit
Suitable for use in tests.
§Panics
Panics if the specified deficit
is zero.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
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
Auto Trait Implementations§
impl Freeze for Error
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<E> ErrorReport for Ewhere
E: Error + 'static,
impl<E> ErrorReport for Ewhere
E: Error + 'static,
Source§fn report(&self) -> Report<ReportHelper<'_>>
fn report(&self) -> Report<ReportHelper<'_>>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more