pub trait CodecErrorExt {
// Required methods
fn unsupported_operation(&self) -> Option<&UnsupportedOperation>;
fn limit_exceeded(&self) -> Option<&LimitExceeded>;
fn find_cause<T: Error + 'static>(&self) -> Option<&T>;
}Expand description
Extension trait for inspecting codec errors.
Blanket-implemented for all core::error::Error + 'static types.
Walks the source() chain to find
common codec error causes without knowing the concrete error type.
Works through any wrapper that delegates source():
thiserror #[from] variants, whereat::At<E>, Box<dyn Error>, etc.
§Example
ⓘ
use zencodec::CodecErrorExt;
let result = dyn_decoder.decode();
if let Err(ref e) = result {
if let Some(limit) = e.limit_exceeded() {
eprintln!("limit exceeded: {limit}");
} else if let Some(op) = e.unsupported_operation() {
eprintln!("not supported: {op}");
}
}Required Methods§
Sourcefn unsupported_operation(&self) -> Option<&UnsupportedOperation>
fn unsupported_operation(&self) -> Option<&UnsupportedOperation>
Find an UnsupportedOperation in this error’s cause chain.
Sourcefn limit_exceeded(&self) -> Option<&LimitExceeded>
fn limit_exceeded(&self) -> Option<&LimitExceeded>
Find a LimitExceeded in this error’s cause chain.
Sourcefn find_cause<T: Error + 'static>(&self) -> Option<&T>
fn find_cause<T: Error + 'static>(&self) -> Option<&T>
Find a cause of arbitrary type T in this error’s cause chain.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.