Skip to main content

fmf_contract/
options.rs

1//! Wire enumerations of `FmfQueryOptions` and `FmfVolumeStatus.state`
2//! (docs/ARCHITECTURE.md opcode table).
3//!
4//! These are the canonical values; fmf-core uses these enums directly (no
5//! wire↔engine mapping layer).
6
7/// Which result column results are ordered by (`FmfQueryOptions.sort_key`).
8#[repr(u32)]
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
10pub enum SortKey {
11    /// Sort by file name.
12    #[default]
13    Name = 0,
14    /// Sort by file size in bytes.
15    Size = 1,
16    /// Sort by last-modified time.
17    Mtime = 2,
18}
19
20/// How the query is matched against names (`FmfQueryOptions.case_mode`).
21#[repr(u32)]
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
23pub enum CaseMode {
24    /// Insensitive unless the query contains an uppercase letter.
25    #[default]
26    Smart = 0,
27    /// Case-insensitive matching.
28    Insensitive = 1,
29    /// Case-sensitive matching.
30    Sensitive = 2,
31}
32
33/// Lifecycle state of a volume's index (`FmfVolumeStatus.state`).
34#[repr(u32)]
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36pub enum VolumeState {
37    /// Initial full scan in progress; the index is not yet complete.
38    Scanning = 0,
39    /// Index is complete and serving queries.
40    Ready = 1,
41    /// A full re-scan is in progress while the prior index keeps serving.
42    Rescanning = 2,
43    /// The volume could not be indexed.
44    Failed = 3,
45}
46
47/// Which haystack a whole-query regex runs against
48/// (`FmfQueryOptions.regex_mode` bit1; ADR-0023).
49#[repr(u32)]
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
51pub enum RegexScope {
52    /// Match against the file name only.
53    #[default]
54    Name = 0,
55    /// Match against the full path.
56    Path = 1,
57}
58
59// Wire u32 → enum, defaulting unknown values like the boundaries always
60// did (pure value conversion — the one place the mapping table lives).
61impl SortKey {
62    /// Decode a wire `u32` into a `SortKey`, defaulting unknown values to `Name`.
63    #[must_use]
64    pub const fn from_u32(v: u32) -> Self {
65        match v {
66            1 => Self::Size,
67            2 => Self::Mtime,
68            _ => Self::Name,
69        }
70    }
71}
72
73impl CaseMode {
74    /// Decode a wire `u32` into a `CaseMode`, defaulting unknown values to `Smart`.
75    #[must_use]
76    pub const fn from_u32(v: u32) -> Self {
77        match v {
78            1 => Self::Insensitive,
79            2 => Self::Sensitive,
80            _ => Self::Smart,
81        }
82    }
83}
84
85impl RegexScope {
86    /// Decode a wire `u32` into a `RegexScope`, defaulting unknown values to `Name`.
87    #[must_use]
88    pub const fn from_u32(v: u32) -> Self {
89        match v {
90            1 => Self::Path,
91            _ => Self::Name,
92        }
93    }
94}