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§
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
Provided Methods§
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