Skip to main content

CodecErrorExt

Trait CodecErrorExt 

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

Source

fn unsupported_operation(&self) -> Option<&UnsupportedOperation>

Find an UnsupportedOperation in this error’s cause chain.

Source

fn limit_exceeded(&self) -> Option<&LimitExceeded>

Find a LimitExceeded in this error’s cause chain.

Source

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.

Implementations on Foreign Types§

Source§

impl CodecErrorExt for dyn Error + 'static

Source§

impl CodecErrorExt for dyn Error + Send + 'static

Source§

impl CodecErrorExt for dyn Error + Send + Sync + 'static

Implementors§

Source§

impl<E: Error + 'static> CodecErrorExt for E