Skip to content

failure::format_err! inside try_stream! strange behavior #22

Closed
@serejkaaa512

Description

@serejkaaa512

If using format_err! macro inside try_stream!:

use failure::*;

pub fn stream() -> impl Stream<Item = failure::Fallible<i32>> + Send {
    async_stream::try_stream! {
        Err(format_err!("adasdasd"))?;
        for i in (1..10) {
            yield 123;
        }
    }
}

It doesn't compile - *mut (dyn std::ops::Fn() + 'static) cannot be shared between threads safely.
But when using it without format_err!:

use failure::*;

#[derive(Debug, Fail)]
#[fail(display = "my error")]
pub struct MyError;

pub fn stream() -> impl Stream<Item = Fallible<i32>> + Send {
    async_stream::try_stream! {
        Err(MyError)?;
        for i in (1..10) {
            yield 123;
        }
    }
}

Compiler says all Ok.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions