[][src]Trait opentracingrust::utils::FailSpan

pub trait FailSpan {
    type Error: Error + ?Sized;
    fn error(&self) -> Option<&Self::Error>;
fn fail_span<S>(self, span: S) -> Self
    where
        S: AsMut<Span>
; }

Trait to make failing spans on error easier and nicer.

The most common use is for Result instances in combination with the ? operator.

Examples

extern crate opentracingrust;

use std::num::ParseIntError;

use opentracingrust::Span;
use opentracingrust::tracers::NoopTracer;
use opentracingrust::utils::FailSpan;
 
fn work(mut span: &mut Span) -> Result<i32, ParseIntError> {
    let ten: i32 = "10".parse().fail_span(&mut span)?;
    let two: i32 = "2".parse().fail_span(&mut span)?;
    Ok(ten * two)
}

fn main() {
    let (tracer, _) = NoopTracer::new();
    let mut span = tracer.span("test");
    let result = work(&mut span).unwrap();
    println!("{}", result);
}

Associated Types

type Error: Error + ?Sized

Loading content...

Required methods

fn error(&self) -> Option<&Self::Error>

Access the current error information, if any.

Returns None if there was no error.

fn fail_span<S>(self, span: S) -> Self where
    S: AsMut<Span>, 

Tags a span as failed if there was an error.

An error event should also be logged with the details following the OpenTracing specification.

Nothing is done if there was no error (error() returns None).

Loading content...

Implementations on Foreign Types

impl<T, E> FailSpan for Result<T, E> where
    E: Error
[src]

type Error = E

Loading content...

Implementors

Loading content...