file_system/fundamentals/
position.rs

1//! File position types for seek operations.
2//!
3//! This module provides the [`Position_type`] enumeration for specifying
4//! file positions during seek operations. It supports absolute positioning
5//! from the start or end of files, as well as relative positioning from
6//! the current file cursor location.
7
8/// Represents a position within a file for seek operations.
9///
10/// This enum provides three different ways to specify a position within a file:
11/// - Absolute position from the beginning of the file
12/// - Relative position from the current cursor location
13/// - Relative position from the end of the file
14///
15/// # Examples
16///
17/// ```rust
18/// use file_system::Position_type;
19///
20/// // Seek to the beginning of the file
21/// let start = Position_type::Start(0);
22///
23/// // Seek 100 bytes from the beginning
24/// let absolute = Position_type::Start(100);
25///
26/// // Move 50 bytes forward from current position
27/// let forward = Position_type::Current(50);
28///
29/// // Move 20 bytes backward from current position
30/// let backward = Position_type::Current(-20);
31///
32/// // Seek to 10 bytes before the end of the file
33/// let near_end = Position_type::End(-10);
34/// ```
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36pub enum Position {
37    /// Absolute position from the start of the file.
38    ///
39    /// The value represents the number of bytes from the beginning of the file.
40    /// A value of 0 positions at the very start of the file.
41    Start(u64),
42
43    /// Relative position from the current cursor location.
44    ///
45    /// Positive values move forward, negative values move backward.
46    /// A value of 0 keeps the current position unchanged.
47    Current(i64),
48
49    /// Relative position from the end of the file.
50    ///
51    /// Negative values position before the end, positive values would position
52    /// beyond the end (which may extend the file if writing is performed).
53    /// A value of 0 positions exactly at the end of the file.
54    End(i64),
55}