Trait FileAccess

Source
pub trait FileAccess:
    AsyncSeek
    + Send
    + Unpin
    + 'static {
    // Required method
    fn poll_read(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        len: usize,
    ) -> Poll<Result<Bytes, Error>>;
}
Expand description

Trait that implements all the necessary file access methods used for serving files.

This trait exists as an alternative to AsyncRead that returns a Bytes directly, potentially eliminating a copy. Unlike AsyncRead, this does mean the implementation is responsible for providing the read buffer.

Required Methods§

Source

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, len: usize, ) -> Poll<Result<Bytes, Error>>

Attempts to read from the file.

If no data is available for reading, the method returns Poll::Pending and arranges for the current task (via cx.waker()) to receive a notification when the object becomes readable or is closed.

An empty Bytes return value indicates EOF.

Implementations on Foreign Types§

Source§

impl FileAccess for Cursor<Bytes>

Source§

fn poll_read( self: Pin<&mut Self>, _cx: &mut Context<'_>, len: usize, ) -> Poll<Result<Bytes, Error>>

Implementors§