pub trait FileObject:
StreamOps
+ ControlOps
+ MemoryMappingOps
+ Selectable {
// Required methods
fn seek(&self, whence: SeekFrom) -> Result<u64, StreamError>;
fn metadata(&self) -> Result<FileMetadata, StreamError>;
fn as_any(&self) -> &dyn Any;
// Provided methods
fn read_at(
&self,
offset: u64,
buffer: &mut [u8],
) -> Result<usize, StreamError> { ... }
fn write_at(&self, offset: u64, buffer: &[u8]) -> Result<usize, StreamError> { ... }
fn truncate(&self, size: u64) -> Result<(), StreamError> { ... }
fn sync(&self) -> Result<(), StreamError> { ... }
}Expand description
Trait for file objects
This trait represents a file-like object that supports stream operations, file-specific operations like seeking and metadata access, control operations for device-specific functionality, and memory mapping operations. Directory reading is handled through normal read() operations.
Required Methods§
Sourcefn seek(&self, whence: SeekFrom) -> Result<u64, StreamError>
fn seek(&self, whence: SeekFrom) -> Result<u64, StreamError>
Seek to a position in the file stream
Sourcefn metadata(&self) -> Result<FileMetadata, StreamError>
fn metadata(&self) -> Result<FileMetadata, StreamError>
Get metadata about the file
fn as_any(&self) -> &dyn Any
Provided Methods§
Sourcefn read_at(&self, offset: u64, buffer: &mut [u8]) -> Result<usize, StreamError>
fn read_at(&self, offset: u64, buffer: &mut [u8]) -> Result<usize, StreamError>
Read data from a specific offset without changing internal position
This method performs a random-access read operation that must not
modify the file’s current seek position. Filesystems that cannot
support position-independent reads may return StreamError::NotSupported.
Sourcefn write_at(&self, offset: u64, buffer: &[u8]) -> Result<usize, StreamError>
fn write_at(&self, offset: u64, buffer: &[u8]) -> Result<usize, StreamError>
Write data to a specific offset without changing internal position
Similar to [read_at], this operation must not adjust the file’s
internal cursor. Implementations can default to returning
StreamError::NotSupported when random-access writes are unavailable.
Sourcefn truncate(&self, size: u64) -> Result<(), StreamError>
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
Sourcefn sync(&self) -> Result<(), StreamError>
fn sync(&self) -> Result<(), StreamError>
Synchronize file content to storage
This method ensures that any buffered changes to the file are written to the underlying storage device. This is important for filesystems that cache file content in memory.
§Returns
Result<(), StreamError>- Ok if the sync was successful
§Errors
StreamError- If the sync operation fails or is not supported