StackErrorExt

Trait StackErrorExt 

Source
pub trait StackErrorExt: StackError + Sized {
    // Provided methods
    fn to_chain<'a>(&'a self) -> ChainWriter<'a> { ... }
    fn to_chain_with_limit<'a>(&'a self, limit: usize) -> ChainWriter<'a> { ... }
    fn last<'a>(&'a self) -> Chain<'a>
       where Self: Sized { ... }
    fn last_stacked(&self) -> &dyn StackError { ... }
    fn first_std(&self) -> Option<&dyn Error> { ... }
}
Expand description

Convenience helpers for types implementing StackError.

Provided Methods§

Source

fn to_chain<'a>(&'a self) -> ChainWriter<'a>

Returns a ChainWriter that walks this error stack from the top and prints a single trailing non- StackError source when formatting.

§Example
let err = StackErrorC::new();
println!("{}", err.to_chain());
// 0: StackError A, at src/main.rs:20:5
// 1: StackError B, at src/main.rs:19:5
// 2: StackError C, at src/main.rs:18:5  
// 3: StdError A
Source

fn to_chain_with_limit<'a>(&'a self, limit: usize) -> ChainWriter<'a>

Returns a ChainWriter capped to limit trailing core::error::Error entries that do not implement StackError.

§Example
let err = StackErrorC::new();
println!("{}", err.to_chain_with_limit(usize::MAX));
// 0: StackError A, at src/main.rs:20:5
// 1: StackError B, at src/main.rs:19:5
// 2: StackError C, at src/main.rs:18:5  
// 3: StdError A
// 4: StdError B
// 5: StdError C

println!("{}", err.to_chain_with_limit(0));
// 0: StackError A, at src/main.rs:20:5
// 1: StackError B, at src/main.rs:19:5
// 2: StackError C, at src/main.rs:18:5  
Source

fn last<'a>(&'a self) -> Chain<'a>
where Self: Sized,

Returns the deepest Chain in the chain.

§Example
0: StackError A, at src/main.rs:20:5
1: StackError B, at src/main.rs:19:5
2: StackError C, at src/main.rs:18:5  
3: StdError A
4: StdError B
5: StdError C <- Return this
Source

fn last_stacked(&self) -> &dyn StackError

Returns the deepest StackError in the chain

§Example
0: StackError A, at src/main.rs:20:5
1: StackError B, at src/main.rs:19:5
2: StackError C, at src/main.rs:18:5  <- Return this
3: StdError A
4: StdError B
5: StdError C
Source

fn first_std(&self) -> Option<&dyn Error>

Returns the first core::error::Error in the chain

§Example
0: StackError A, at src/main.rs:20:5
1: StackError B, at src/main.rs:19:5
2: StackError C, at src/main.rs:18:5
3: StdError A <- Return this
4: StdError B
5: StdError C

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.

Implementors§