Skip to main content

AsyncFileReader

Struct AsyncFileReader 

Source
pub struct AsyncFileReader { /* private fields */ }
Expand description

Type-erased asynchronous byte input associated with an opened file.

Asynchronous providers must report temporary unavailability as Poll::Pending and arrange to wake the registered task. Returning WouldBlock or Interrupted violates the async I/O contract. The safe qubit-io read methods expose these errors as InvalidData while retaining the original cause chain. Consequently, read_all and read_prefix classify them as FsErrorKind::Io; they do not promote a nested FsError to the outer error or promise that a nested error’s type/effect is recoverable through Error::source. A directly transported typed business error keeps its type, kind, provider, and effect state, but a failed read may already have changed the caller’s buffer, so its kind does not prove that the buffer is unchanged. Synchronous interruption retry rules do not apply to asynchronous inputs.

§Examples

The application supplies a configured filesystem and a validated path.

use qubit_fs::AsyncFileSystem;
use qubit_fs::Path;
use qubit_fs::read::ReadOptions;
use qubit_io::AsyncInput;

async fn read_prefix(
    filesystem: &AsyncFileSystem,
    path: &Path,
) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
    let mut reader = filesystem.open_reader(path, ReadOptions::default()).await?;
    let mut prefix = vec![0; 16];
    let count = reader.read_fully_async(&mut prefix).await?;
    prefix.truncate(count);
    Ok(prefix)
}

Implementations§

Source§

impl AsyncFileReader

Source

pub fn info(&self) -> &OpenedFileInfo

Returns the fixed identity and open-time metadata snapshot.

§Returns

Information captured when the reader was opened.

Trait Implementations§

Source§

impl AsyncInput for AsyncFileReader

Source§

type Item = u8

Byte value yielded by this asynchronous reader.

Source§

fn is_buffered(&self) -> bool

Reports whether the provider input can satisfy reads from buffered data.

§Returns

true when the wrapped input already buffers bytes for subsequent reads.

Source§

unsafe fn poll_read_unchecked( self: Pin<&mut Self>, cx: &mut Context<'_>, output: &mut [u8], index: usize, count: usize, ) -> Poll<IoResult<usize>>

Polls the provider input using the caller’s unsafe range contract.

§Parameters
  • cx: Task context used to register readiness when the read is pending.
  • output: Destination storage receiving the read bytes.
  • index: Start of the destination range.
  • count: Maximum number of bytes requested.
§Returns

The wrapped input’s pending state or its ready byte count/error.

§Safety

index..index + count must be a valid range within output, and the addition must not overflow.

Source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, output: &mut [Self::Item], ) -> Poll<Result<usize, Error>>

Polls a read into the full destination slice. Read more
Source§

fn read_async<'a>( &'a mut self, output: &'a mut [Self::Item], ) -> ReadFuture<'a, Self> ⓘ
where Self: Sized + Unpin,

Creates a future that performs one asynchronous read operation. Read more
Source§

fn read_fully_async<'a>( &'a mut self, output: &'a mut [Self::Item], ) -> ReadFullyFuture<'a, Self> ⓘ
where Self: Sized + Unpin,

Creates a future that fills a destination as far as possible. Read more
Source§

fn read_exactly_async<'a>( &'a mut self, output: &'a mut [Self::Item], ) -> ReadExactFuture<'a, Self> ⓘ
where Self: Sized + Unpin,

Creates a future that fills the entire destination. Read more
Source§

impl Debug for AsyncFileReader

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult

Formats the open-time file information without exposing the input.

§Parameters
  • formatter: Destination for the debug representation.

Auto Trait Implementations§

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> AsyncByteInput for T
where T: AsyncInput<Item = u8> + ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.