[][src]Trait snafu::futures01::FutureExt

pub trait FutureExt: Future + Sized {
    pub fn context<C, E>(self, context: C) -> Context<Self, C, E>
    where
        C: IntoError<E, Source = Self::Error>,
        E: Error + ErrorCompat
;
pub fn with_context<F, C, E>(self, context: F) -> WithContext<Self, F, E>
    where
        F: FnOnce() -> C,
        C: IntoError<E, Source = Self::Error>,
        E: Error + ErrorCompat
; }

Additions to Future.

Required methods

pub fn context<C, E>(self, context: C) -> Context<Self, C, E> where
    C: IntoError<E, Source = Self::Error>,
    E: Error + ErrorCompat
[src]

Extend a Future's error with additional context-sensitive information.

use futures::Future;
use snafu::{futures01::FutureExt, Snafu};

#[derive(Debug, Snafu)]
enum Error {
    Authenticating {
        user_name: String,
        user_id: i32,
        source: ApiError,
    },
}

fn example() -> impl Future<Item = i32, Error = Error> {
    another_function().context(Authenticating {
        user_name: "admin",
        user_id: 42,
    })
}

fn another_function() -> impl Future<Item = i32, Error = ApiError> {
    /* ... */
}

Note that the context selector will call Into::into on each field, so the types are not required to exactly match.

pub fn with_context<F, C, E>(self, context: F) -> WithContext<Self, F, E> where
    F: FnOnce() -> C,
    C: IntoError<E, Source = Self::Error>,
    E: Error + ErrorCompat
[src]

Extend a Future's error with lazily-generated context-sensitive information.

use futures::Future;
use snafu::{futures01::FutureExt, Snafu};

#[derive(Debug, Snafu)]
enum Error {
    Authenticating {
        user_name: String,
        user_id: i32,
        source: ApiError,
    },
}

fn example() -> impl Future<Item = i32, Error = Error> {
    another_function().with_context(|| Authenticating {
        user_name: "admin".to_string(),
        user_id: 42,
    })
}

fn another_function() -> impl Future<Item = i32, Error = ApiError> {
    /* ... */
}

Note that this may not be needed in many cases because the context selector will call Into::into on each field.

Loading content...

Implementors

impl<Fut> FutureExt for Fut where
    Fut: Future
[src]

Loading content...