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§
Sourcefn to_chain<'a>(&'a self) -> ChainWriter<'a>
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
Sourcefn to_chain_with_limit<'a>(&'a self, limit: usize) -> ChainWriter<'a>
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
Sourcefn last_stacked(&self) -> &dyn StackError
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
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.