Skip to content

Missing function to generate a TryStream from an iterator? #2923

@petekubiak

Description

@petekubiak

I'm trying to generate a stream to work on a &mut [u8]. To do this I've tried to use:

async fn process(buffer: &mut [u8]) -> Result<(), MyError> {
    stream::iter(buffer).enumerate().try_for_each(async |(index, element)| {
        *element = fallible_read(index).await?;
        Ok(())
     })
}

but I get an error on try_for_each saying that "the method try_for_each exists for struct Enumerate<Iter<IterMut<'_, u8>>>, but its trait bounds were not satisfied"

There is also the following information:

note: the following trait bounds were not satisfied:
            `futures::stream::Enumerate<futures::stream::Iter<core::slice::IterMut<'_, u8>>>: TryStream`
            which is required by `futures::stream::Enumerate<futures::stream::Iter<core::slice::IterMut<'_, u8>>>: TryStreamExt`
            `&futures::stream::Enumerate<futures::stream::Iter<core::slice::IterMut<'_, u8>>>: TryStream`
            which is required by `&futures::stream::Enumerate<futures::stream::Iter<core::slice::IterMut<'_, u8>>>: TryStreamExt`
            `&mut futures::stream::Enumerate<futures::stream::Iter<core::slice::IterMut<'_, u8>>>: TryStream`
            which is required by `&mut futures::stream::Enumerate<futures::stream::Iter<core::slice::IterMut<'_, u8>>>: TryStreamExt`

Is there a missing function which generates a TryStream from an iterator rather than a Stream? E.g. stream::try_iter or something? Or am I just using this wrong?

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