Skip to main content

ResultAtExt

Trait ResultAtExt 

Source
pub trait ResultAtExt<T, E> {
    // Required methods
    fn at(self) -> Result<T, At<E>>;
    fn at_str(self, msg: &'static str) -> Result<T, At<E>>;
    fn at_string(self, f: impl FnOnce() -> String) -> Result<T, At<E>>;
    fn at_data<C>(self, f: impl FnOnce() -> C) -> Result<T, At<E>>
       where C: Display + Send + Sync + 'static;
    fn at_debug<C>(self, f: impl FnOnce() -> C) -> Result<T, At<E>>
       where C: Debug + Send + Sync + 'static;
    fn at_error<Err>(self, err: Err) -> Result<T, At<E>>
       where Err: Error + Send + Sync + 'static;
    fn at_crate(self, info: &'static AtCrateInfo) -> Result<T, At<E>>;
    fn at_fn<F>(self, marker: F) -> Result<T, At<E>>
       where F: Fn();
    fn at_named(self, name: &'static str) -> Result<T, At<E>>;
    fn map_err_at<E2, F>(self, f: F) -> Result<T, At<E2>>
       where F: FnOnce(E) -> E2;
}
Expand description

Extension trait for adding location tracking to Result<T, At<E>>.

§Example

use whereat::{at, At, ResultAtExt};

#[derive(Debug)]
enum MyError { Oops }

fn inner() -> Result<(), At<MyError>> {
    Err(at(MyError::Oops))
}

fn outer() -> Result<(), At<MyError>> {
    inner().at()?;
    Ok(())
}

Required Methods§

Source

fn at(self) -> Result<T, At<E>>

Add the caller’s location to the error trace if this is Err.

Source

fn at_str(self, msg: &'static str) -> Result<T, At<E>>

Add static string context to last location (or create one if empty).

Source

fn at_string(self, f: impl FnOnce() -> String) -> Result<T, At<E>>

Add lazily-computed string context to last location (or create one if empty).

Source

fn at_data<C>(self, f: impl FnOnce() -> C) -> Result<T, At<E>>
where C: Display + Send + Sync + 'static,

Add lazily-computed typed context (Display) to last location (or create one if empty).

Source

fn at_debug<C>(self, f: impl FnOnce() -> C) -> Result<T, At<E>>
where C: Debug + Send + Sync + 'static,

Add lazily-computed typed context (Debug) to last location (or create one if empty).

Source

fn at_error<Err>(self, err: Err) -> Result<T, At<E>>
where Err: Error + Send + Sync + 'static,

Add an error as context to the last location (or create one if empty).

Source

fn at_crate(self, info: &'static AtCrateInfo) -> Result<T, At<E>>

Add crate boundary marker to last location (or create one if empty).

Source

fn at_fn<F>(self, marker: F) -> Result<T, At<E>>
where F: Fn(),

Add a location frame with the caller’s function name as context.

Captures both file:line:col AND the function name at zero runtime cost. Pass an empty closure || {} - its type includes the parent function name.

Source

fn at_named(self, name: &'static str) -> Result<T, At<E>>

Add a location frame with an explicit name as context.

Like at_fn but with an explicit label.

Source

fn map_err_at<E2, F>(self, f: F) -> Result<T, At<E2>>
where F: FnOnce(E) -> E2,

Convert the error type while preserving the trace.

This is a convenience method that combines map_err with At::map_error.

§Example
use whereat::{at, At, ResultAtExt};

#[derive(Debug)]
struct InternalError;
#[derive(Debug)]
struct PublicError;

fn internal() -> Result<(), At<InternalError>> {
    Err(at(InternalError))
}

fn public() -> Result<(), At<PublicError>> {
    // Clean conversion that preserves trace
    internal().map_err_at(|_| PublicError)?;
    Ok(())
}

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<T, E> ResultAtExt<T, E> for Result<T, At<E>>

Source§

fn at(self) -> Result<T, At<E>>

Source§

fn at_str(self, msg: &'static str) -> Result<T, At<E>>

Source§

fn at_string(self, f: impl FnOnce() -> String) -> Result<T, At<E>>

Source§

fn at_data<C>(self, f: impl FnOnce() -> C) -> Result<T, At<E>>
where C: Display + Send + Sync + 'static,

Source§

fn at_debug<C>(self, f: impl FnOnce() -> C) -> Result<T, At<E>>
where C: Debug + Send + Sync + 'static,

Source§

fn at_error<Err>(self, err: Err) -> Result<T, At<E>>
where Err: Error + Send + Sync + 'static,

Source§

fn at_crate(self, info: &'static AtCrateInfo) -> Result<T, At<E>>

Source§

fn at_fn<F>(self, marker: F) -> Result<T, At<E>>
where F: Fn(),

Source§

fn at_named(self, name: &'static str) -> Result<T, At<E>>

Source§

fn map_err_at<E2, F>(self, f: F) -> Result<T, At<E2>>
where F: FnOnce(E) -> E2,

Implementors§