pub trait FileAllocate: FileOperation {
// Required method
fn file_allocate(
&self,
file: &Self::File,
offset: u64,
length: u64,
mode: AllocationMode,
cancellation: &Cancellation,
) -> impl Future<Output = OperationResult<()>> + Send;
}Expand description
Optional file-space reservation capability, with Linux fallocate semantics for ordinary allocation and KEEP_SIZE.
This optional capability has Linux-style semantics. Backends omit its implementation where these semantics are unsupported, allowing generic consumers to require support at compile time. Filesystem and per-file support still vary at runtime; their errors are preserved. Allocation is not emulated by resizing or writing zeros.
An allocation-only adapter does not need to forward the core file operations:
use base_scheduler::{AllocationMode, Cancellation, FileAllocate, FileOperation, OperationResult};
struct AllocationOnly<S>(S);
impl<S: FileAllocate> FileOperation for AllocationOnly<S> {
type File = S::File;
}
impl<S: FileAllocate> FileAllocate for AllocationOnly<S> {
async fn file_allocate(&self, file: &Self::File, offset: u64, length: u64, mode: AllocationMode, cancellation: &Cancellation) -> OperationResult<()> {
self.0.file_allocate(file, offset, length, mode, cancellation).await
}
}Required Methods§
Sourcefn file_allocate(
&self,
file: &Self::File,
offset: u64,
length: u64,
mode: AllocationMode,
cancellation: &Cancellation,
) -> impl Future<Output = OperationResult<()>> + Send
fn file_allocate( &self, file: &Self::File, offset: u64, length: u64, mode: AllocationMode, cancellation: &Cancellation, ) -> impl Future<Output = OperationResult<()>> + Send
Reserve backing space for [offset, offset + length) on a writable file. Extend grows the logical length when necessary; KeepSize preserves it. Both modes preserve existing contents and the shared cursor. Subsequent writes in the reserved range have the underlying filesystem’s allocation guarantee against running out of space.
Length must be positive and the range end must fit in i64; invalid ranges return InvalidInput. Filesystem limits and errors, including unsupported allocation, are reported. This does not unshare copy-on-write extents, guarantee durability, or order concurrent file operations. Await related operations sequentially and use file_sync for synchronization.
The future is lazy. Cancellation before dispatch prevents submission, and blocking workers check again before execution. Started blocking operations preserve their actual result; native cancellation is best effort, with successful completion winning concurrent cancellation. The backend retains the file until access ends even if the waiting future is dropped. Errors or cancellation do not promise rollback of partial filesystem changes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".