Skip to main content

FileTruncate

Trait FileTruncate 

Source
pub trait FileTruncate: FileOperation {
    // Required method
    fn file_truncate(
        &self,
        file: &Self::File,
        length: u64,
        cancellation: &Cancellation,
    ) -> impl Future<Output = OperationResult<()>> + Send;
}
Expand description

Change the logical length of an already-open file resource.

Required Methods§

Source

fn file_truncate( &self, file: &Self::File, length: u64, cancellation: &Cancellation, ) -> impl Future<Output = OperationResult<()>> + Send

Set the logical file length, discarding bytes when shrinking and filling an extension with zeros. The file must be open for writing. Lengths must fit in i64; filesystem limits and other OS errors are reported. The shared cursor is unchanged, even when it ends up past EOF.

The future is lazy. Cancellation before dispatch prevents submission; blocking workers check again before execution. Once submitted, cancellation is best effort and successful completion wins a concurrent request. The backend retains the file until access ends, and dropping a waiter cannot undo a completed resize.

Await reads, writes, seeks, and truncation sequentially when ordering matters. This operation does not guarantee disk-space reservation or durability; use file_sync after completion when synchronization is needed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§