[][src]Trait snafu::futures::try_stream::TryStreamExt

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

Additions to TryStream.

Required methods

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

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

use futures::TryStream;
use snafu::{futures::TryStreamExt, Snafu};

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

fn example() -> impl TryStream<Ok = i32, Error = Error> {
    stock_prices().context(Authenticating {
        user_name: "admin",
        user_id: 42,
    })
}

fn stock_prices() -> impl TryStream<Ok = 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: FnMut() -> C,
    C: IntoError<E, Source = Self::Error>,
    E: Error + ErrorCompat
[src]

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

use futures::TryStream;
use snafu::{futures::TryStreamExt, Snafu};

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

fn example() -> impl TryStream<Ok = i32, Error = Error> {
    stock_prices().with_context(|| Authenticating {
        user_name: "admin",
        user_id: 42,
    })
}

fn stock_prices() -> impl TryStream<Ok = 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<St> TryStreamExt for St where
    St: TryStream
[src]

Loading content...