Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

xamgore
Copy link
Contributor

@xamgore xamgore commented May 25, 2025

This crate when being compiled with:

  • unblock feature on
  • tempfile feature off

Gets an error message:

std::io::Cursor::new(self.content)
the trait AsyncRead is not implemented for std::io::Cursor<bytes::Bytes>

Lucky us, futures_util has a wrapper type just for that.

/// Convert to a `AsyncRead`.
#[cfg(feature = "unblock")]
#[cfg_attr(docsrs, doc(cfg(feature = "unblock")))]
pub fn into_async_read(self) -> impl AsyncRead + Sync + Send + 'static {
    #[cfg(feature = "tempfile")]
    {
        blocking::Unblock::new(self.content)
    }

    #[cfg(not(feature = "tempfile"))]
    {
        futures_util::io::Cursor::new(self.content)
    }
}

It returns futures_io::if_std::AsyncRead. The trait is implemented for the futures_util::io::Cursor.

…1263)

This crate when being compiled with:
- `unblock` feature on
- `tempfile` feature off

Gets an error message:
> std::io::Cursor::new(self.content)
> the trait `AsyncRead` is not implemented for `std::io::Cursor<bytes::Bytes>`

Lucky us, `futures_util` has a wrapper type just for that.
@xamgore xamgore changed the title Wrap the Upload buffer with an AsyncRead cursor (fix #1263) WIP: Wrap the Upload buffer with an AsyncRead cursor (fix #1263) May 25, 2025
@xamgore xamgore closed this May 25, 2025
@xamgore xamgore reopened this May 26, 2025
@xamgore xamgore changed the title WIP: Wrap the Upload buffer with an AsyncRead cursor (fix #1263) Wrap the Upload buffer with an AsyncRead cursor (fix #1263) May 26, 2025
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.

1 participant