Trait FileObject

Source
pub trait FileObject: StreamOps {
    // Required methods
    fn seek(&self, whence: SeekFrom) -> Result<u64, StreamError>;
    fn metadata(&self) -> Result<FileMetadata, StreamError>;

    // Provided method
    fn truncate(&self, size: u64) -> Result<(), StreamError> { ... }
}
Expand description

Trait for file objects

This trait represents a file-like object that supports both stream operations and file-specific operations like seeking and metadata access. Directory reading is handled through normal read() operations.

Required Methods§

Source

fn seek(&self, whence: SeekFrom) -> Result<u64, StreamError>

Seek to a position in the file stream

Source

fn metadata(&self) -> Result<FileMetadata, StreamError>

Get metadata about the file

Provided Methods§

Source

fn truncate(&self, size: u64) -> Result<(), StreamError>

Truncate the file to the specified size

This method changes the size of the file to the specified length. If the new size is smaller than the current size, the file is truncated. If the new size is larger, the file is extended with zero bytes.

§Arguments
  • size - New size of the file in bytes
§Returns
  • Result<(), StreamError> - Ok if the file was truncated successfully
§Errors
  • StreamError - If the file is a directory or the operation is not supported

Implementors§