Skip to main content

Trace

Trait Trace 

Source
pub trait Trace:
    Sized
    + Send
    + Sync
    + 'static {
    // Required method
    fn trace<R>(self, trace: R) -> Self
       where R: Debug + Display + Send + Sync + 'static;
}
Expand description

An error type which can add additional “trace” information to itself.

Some functions only add additional context to errors created by other functions, rather than creating errors themselves. With generics, it’s therefore possible to have a generic function which can produce errors with some type arguments but not with others. In these cases, Trace allows those functions to add context if an error can occur, and compile out the context if the error type is Infallible or Panic.

§Example

use rancor::{ResultExt, Trace};

trait Print<E> {
    fn print(&self, message: &str) -> Result<(), E>;
}

fn print_hello_world<T: Print<E>, E: Trace>(printer: &T) -> Result<(), E> {
    printer.print("hello").trace("failed to print hello")?;
    printer.print("world").trace("failed to print world")?;
    Ok(())
}

Required Methods§

Source

fn trace<R>(self, trace: R) -> Self
where R: Debug + Display + Send + Sync + 'static,

Adds an additional trace to this error, returning a new error.

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§