Skip to main content

fren_date/
plan_types.rs

1//! Core data types describing a rename batch.
2
3use std::ffi::OsString;
4use std::path::PathBuf;
5use uuid::Uuid;
6
7/// What kind of filesystem item a plan refers to.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum ItemKind {
10    /// Regular file.
11    File,
12    /// Directory.
13    Dir,
14    /// Symbolic link (treated as a file; never followed).
15    Symlink,
16}
17
18/// What kind of date was detected inside a filename.
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum DateKind {
21    /// Year-month only (e.g. `1975-08`).
22    MonthOnly,
23    /// Full calendar date (e.g. `2017-12-30`).
24    DateOnly,
25    /// Calendar date with time component (e.g. `2017-12-30T10-44-56`).
26    DateTime,
27}
28
29/// A date span detected inside a filename. `byte_span` is recorded so a
30/// future caller can locate the date and move it within the name.
31#[derive(Debug, Clone)]
32pub struct DetectedDate {
33    /// Byte range (in the slugified pre-substitution string) where the
34    /// date was found.
35    pub byte_span: std::ops::Range<usize>,
36    /// Parsed date/time.
37    pub parsed: chrono::NaiveDateTime,
38    /// Pendulum-style format string from `POSSIBLE_FORMATS`.
39    pub original_format: &'static str,
40    /// Granularity of the detected date.
41    pub kind: DateKind,
42}
43
44/// A single planned rename operation. Produced by the planner; consumed by
45/// the executor in bottom-up order.
46#[derive(Debug, Clone)]
47pub struct RenamePlan {
48    /// Path of the item at planning time.
49    pub original_path: PathBuf,
50    /// Parent directory at planning time.
51    pub parent: PathBuf,
52    /// Original name (just the last path component).
53    pub old_name: OsString,
54    /// Target name (just the last component, in the new parent).
55    pub new_name: OsString,
56    /// Depth of the original path relative to the batch root. Used by the
57    /// executor to enforce the bottom-up invariant (deeper paths first).
58    pub depth: usize,
59    /// What kind of item this is.
60    pub kind: ItemKind,
61    /// If a date was detected during slugification, captured here so the
62    /// reorder phase can locate and move it.
63    pub detected_date: Option<DetectedDate>,
64    /// UUID grouping all plans of the same batch.
65    pub batch_id: Uuid,
66}