Skip to content

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
and also make AsyncInputStream Send and Sync by switching the internal
OnceCell to OnceLock.
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
2 participants