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
impl AsyncFileReader
Sourcepub fn info(&self) -> &OpenedFileInfo
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
impl AsyncInput for AsyncFileReader
Source§fn is_buffered(&self) -> bool
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>>
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.