Skip to content

add some futures_core::stream::Stream impls for AsyncInputStream#80

Merged
pchickey merged 3 commits intomainfrom
pch/futures_core_stream_impls
Oct 9, 2025
Merged

add some futures_core::stream::Stream impls for AsyncInputStream#80
pchickey merged 3 commits intomainfrom
pch/futures_core_stream_impls

Conversation

@pchickey
Copy link
Contributor

@pchickey pchickey commented Aug 8, 2025

WIP: This PR still needs some tests

Closes #77

/// items of `Result<Vec<u8>, std::io::Error>`. The returned byte vectors
/// will be at most 8k. If you want to control chunk size, use
/// `Self::into_stream_of`.
pub fn into_stream(self) -> AsyncInputChunkStream {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling into_stream() on an AsyncInputStream feels odd. 😆

Could this instead be:

impl AsyncInputChunkStream {
    pub fn new(stream: AsyncInputStream) -> Self {
        Self {
            stream,
            chunk_size: 8 * 1024,
        }
    }

    pub fn with_size(stream: AsyncInputStream, chunk_size: usize) -> Self {
        Self {
            stream,
            chunk_size,
        }
    }
}

which makes it somewhat analogous to Vec::new and Vec::with_capacity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think anyone wants to think about AsyncInputChunkStream as a type itself, I would make it a private type and just return impl Stream<Item = ...> since that is all that matters, except we need to return a concrete type in case the user wants the into_inner method on the ChunkStream/ByteStream. I don't think the analogy to Vec really holds much water.

@pchickey pchickey force-pushed the pch/futures_core_stream_impls branch from c4d90f6 to e781d6b Compare August 11, 2025 19:33
@pchickey pchickey mentioned this pull request Oct 9, 2025
and also make AsyncInputStream Send and Sync by switching the internal
OnceCell to OnceLock.
@pchickey pchickey force-pushed the pch/futures_core_stream_impls branch from 92a2d27 to 24cf772 Compare October 9, 2025 19:15
@pchickey pchickey merged commit 42b1426 into main Oct 9, 2025
5 checks passed
@pchickey pchickey deleted the pch/futures_core_stream_impls branch October 9, 2025 23:27
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

Successfully merging this pull request may close these issues.

futures_core::Stream interop

3 participants