Trait genfs::File [] [src]

pub trait File {
    type Error;
    fn read(&self, buf: &mut [u8]) -> Result<usize, Self::Error>;
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>;
fn flush(&mut self) -> Result<(), Self::Error>;
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error>; }

A reference to an open file on the filesystem.

An instance of a File can be read and/or written depending on what options it was opened with.

Files should be automatically closed when they go out of scope.

Associated Types

The type that represents the set of all errors that can occur during reading or writing.

Required Methods

Pull some bytes from this source into the specified buffer, returning how many bytes were read.

This function does not provide any guarantees about whether it blocks waiting for data, but if an object needs to block for a read but cannot it will typically signal this via an Err return value.

If the return value of this method is Ok(n), then it must be guaranteed that 0 <= n <= buf.len(). A nonzero n value indicates that the buffer buf has been filled in with n bytes of data from this source. If n is 0, then it can indicate one of two scenarios:

  1. This reader has reached its "end of file" and will likely no longer be able to produce bytes. Note that this does not mean that the reader will always no longer be able to produce bytes.
  2. The buffer specified was 0 bytes in length.

No guarantees are provided about the contents of buf when this function is called, implementations cannot rely on any property of the contents of buf being true. It is recommended that implementations only write data to buf instead of reading its contents.

Errors

If this function encounters any form of I/O or other error, an error variant will be returned.

Write a buffer into this object, returning how many bytes were written.

This function will attempt to write the entire contents of buf, but the entire write may not succeed, or the write may also generate an error. A call to write represents at most one attempt to write to any wrapped object.

Calls to write are not guaranteed to block waiting for data to be written, and a write which would otherwise block can be indicated through an Err variant.

If the return value is Ok(n) then it must be guaranteed that 0 <= n <= buf.len(). A return value of 0 typically means that the underlying object is no longer able to accept bytes and will likely not be able to in the future as well, or that the buffer provided is empty.

Errors

Each call to write may generate an I/O error indicating that the operation could not be completed.

It is not considered an error if the entire buffer could not be written to this writer.

Flush this output stream, ensuring that all intermediately buffered contents reach their destination.

Errors

It is considered an error if not all bytes could be written due to I/O errors or EOF being reached.

Seek to an offset, in bytes, in a stream.

A seek beyond the end of a stream is allowed, but implementation defined.

If the seek operation completed successfully, this method returns the new position from the start of the stream. That position can be used later with SeekFrom::Start.

Errors

Seeking to a negative offset is considered an error.

Implementors