Skip to main content

base_scheduler/
file_seek.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use super::FileOperation;
5use crate::{Cancellation, OperationResult};
6use std::{future::Future, io::SeekFrom};
7
8/// Inspect or reposition a file resource's shared cursor.
9pub trait FileSeek: FileOperation {
10    /// Reposition the shared cursor and return its resulting byte offset. `SeekFrom::Current(0)` queries the position; seeking past EOF does not extend the file. Absolute offsets must fit in `i64`; invalid positions and OS limits return errors.
11    ///
12    /// Await cursor operations sequentially when ordering matters. A seek followed by a read or write is not atomic with respect to other users of the resource. Cancellation before execution prevents seeking; once started, the actual result is preserved, and dropping the future does not undo the seek.
13    fn file_seek(
14        &self,
15        file: &Self::File,
16        position: SeekFrom,
17        cancellation: &Cancellation,
18    ) -> impl Future<Output = OperationResult<u64>> + Send;
19}