Skip to main content

FuturesIo

Struct FuturesIo 

Source
pub struct FuturesIo<S> { /* private fields */ }
Expand description

Bridges futures_io::{AsyncRead, AsyncWrite}hyper::rt::{Read, Write}.

hyper-util only ships TokioIo; smol-hyper 0.1.1 has been dead since 2023-12-29 and bridges in the opposite direction. Without this bridge, the smol backend doesn’t exist.

The implementation is unsafe-free: it reads into a scratch buffer and copies out through the safe ReadBufCursor::put_slice — exactly the technique hyper::rt::Read’s documentation recommends. The cost is one copy per read; zero-copy would require unsafe (ReadBufCursor::as_mut/advance), and the crate declares #![forbid(unsafe_code)] — deliberately deferred.

Implementations§

Source§

impl<S> FuturesIo<S>

Source

pub fn new(inner: S) -> Self

Source

pub fn into_inner(self) -> S

Source

pub fn get_ref(&self) -> &S

Trait Implementations§

Source§

impl<S: Debug> Debug for FuturesIo<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: AsyncRead + Unpin> Read for FuturesIo<S>

Source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: ReadBufCursor<'_>, ) -> Poll<Result<()>>

Attempts to read bytes into the buf. Read more
Source§

impl<S: AsyncWrite + Unpin> Write for FuturesIo<S>

Source§

fn is_write_vectored(&self) -> bool

futures_io::AsyncWrite gives no way to ask S whether its vectored write is efficient: the trait has no is_write_vectored method at all — only poll_write, poll_write_vectored, poll_flush, poll_close. The default poll_write_vectored implementation in futures-io 0.3.33 writes only the first non-empty buffer (futures_io::AsyncWrite::poll_write_vectored, checked against the dependency’s source); for any S that hasn’t overridden it, a vectored write silently degrades into one ordinary write — more syscalls, not fewer.

hyper documents this method as a promise of an “efficient” poll_write_vectored implementation and branches on it to decide whether to coalesce buffers before writing. Returning true here would assert something we have no way to back up — and a capability that lies is worse than one that’s absent, because the calling code (here, hyper itself) branches on it. The honest, conservative answer is false.

If a concrete S shows up for which vectored writes are provably efficient, the right path is a separate constructor with an explicit opt-in, not an optimistic default here. There is no such consumer today, so adding one would be speculative API with no caller.

Source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the destination. Read more
Source§

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempts to flush the object. Read more
Source§

fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempts to shut down this writer.
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize>>

Like poll_write, except that it writes from a slice of buffers.

Auto Trait Implementations§

§

impl<S> Freeze for FuturesIo<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for FuturesIo<S>
where S: RefUnwindSafe,

§

impl<S> Send for FuturesIo<S>
where S: Send,

§

impl<S> Sync for FuturesIo<S>
where S: Sync,

§

impl<S> Unpin for FuturesIo<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for FuturesIo<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for FuturesIo<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.