Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for an empty stream for stubbing #94

Open
ydirson opened this issue Mar 20, 2023 · 2 comments
Open

Example for an empty stream for stubbing #94

ydirson opened this issue Mar 20, 2023 · 2 comments

Comments

@ydirson
Copy link

ydirson commented Mar 20, 2023

I'm working on a project where I use async_stream for interfacing with an optional crate. I wish to propose a stub for platforms that don't have support for this crate.

The following naive attempt does not work (the compiler tells me I'd rather use unit type as return value), likely because the lack of a yield does not allow the macro to derive an iterm type:

    pub fn stream(&mut self) -> impl Stream<Item = io::Result<NetEvent>> + '_ {
        try_stream! {
        }
    }

How can I achieve that ?

@Darksonn
Copy link

You can use futures::stream::empty::<io::Result<NetEvent>>()

@ydirson
Copy link
Author

ydirson commented Mar 22, 2023

That works great, thanks!
Maybe a note about this case and this solution could fit in the doc ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants