pub trait OofExt<T>: Sized {
fn _tag<Tag: 'static>(self) -> Result<T, OofBuilder>;
fn _tag_if<Tag: 'static, F: FnOnce(&Box<dyn Send + Sync + Error + 'static>) -> bool>(
self,
f: F
) -> Result<T, OofBuilder>;
fn _attach<D: Debug>(self, debuggable: D) -> Result<T, OofBuilder>;
fn _attach_lazy<D: ToString, F: FnOnce() -> D>(
self,
f: F
) -> Result<T, OofBuilder>;
}Expand description
Helper trait for Result and Option to add tags and attach extra contexts.
Ex)
use oofs::{oofs, Oof, OofExt};
struct MyTag;
#[oofs]
fn some_fn(x: usize) -> Result<u64, Oof> {
let ret = "hello world"
.parse::<u64>()
._tag::<MyTag>() // tags the error with the type `RetryTag`.
._attach(x) // attach anything that implements `Debug` as custom context.
._attach_lazy(|| "extra context")?; // lazily evaluate context; useful for something like `|| serde_json::to_string(&x)`.
Ok(ret)
}Required Methods
sourcefn _tag<Tag: 'static>(self) -> Result<T, OofBuilder>
fn _tag<Tag: 'static>(self) -> Result<T, OofBuilder>
Tag the given type that can be searched with .tagged_nested::<T>() in the higher level call.
sourcefn _tag_if<Tag: 'static, F: FnOnce(&Box<dyn Send + Sync + Error + 'static>) -> bool>(
self,
f: F
) -> Result<T, OofBuilder>
fn _tag_if<Tag: 'static, F: FnOnce(&Box<dyn Send + Sync + Error + 'static>) -> bool>(
self,
f: F
) -> Result<T, OofBuilder>
Tag the given type if the closure evaluates to true.
sourcefn _attach<D: Debug>(self, debuggable: D) -> Result<T, OofBuilder>
fn _attach<D: Debug>(self, debuggable: D) -> Result<T, OofBuilder>
Attach any value that implements std::fmt::Debug.
This attached value will be listed as attachments in the displayed error.
Ex)
let x = 123u8;
"hello world"
.parse::<usize>()
._attach(x)
._attach("some attachment")?;Above example will output:
$0.parse() failed at `oofs/tests/basic.rs:11:11`
Parameters:
$0: &str = "hello world"
Attachments:
0: 123
1: "some attachment"
Caused by:
invalid digit found in stringsourcefn _attach_lazy<D: ToString, F: FnOnce() -> D>(
self,
f: F
) -> Result<T, OofBuilder>
fn _attach_lazy<D: ToString, F: FnOnce() -> D>(
self,
f: F
) -> Result<T, OofBuilder>
Lazily load and attach any value that implements ToString.
This attached value will be listed as attachments in the displayed error.
Ex)
"hello world"
.parse::<usize>()
._attach_lazy(|| "some attachment")?;Above example will output:
$0.parse() failed at `oofs/tests/basic.rs:11:11`
Parameters:
$0: &str = "hello world"
Attachments:
0: "some attachment"
Caused by:
invalid digit found in string