diff --git a/core/dr-types/Cargo.toml b/core/dr-types/Cargo.toml index 6d3b337..97b2c69 100644 --- a/core/dr-types/Cargo.toml +++ b/core/dr-types/Cargo.toml @@ -7,3 +7,7 @@ license.workspace = true [dependencies] thiserror.workspace = true +# Selectors are stored as JSON in `collections.selector_json` and travel in +# sync'd cache rules, so the predicate language has to serialise. Derive-only: +# no serde machinery leaks into the rest of `core/`. +serde.workspace = true diff --git a/core/dr-types/src/lib.rs b/core/dr-types/src/lib.rs index dca189d..1fcb833 100644 --- a/core/dr-types/src/lib.rs +++ b/core/dr-types/src/lib.rs @@ -14,7 +14,8 @@ pub use selector::{ColourLabel, DateSelector, FlagState, Selector, Tier}; /// Identifies a granted library location — a directory on Linux, a persisted /// document tree on Android. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] +#[serde(transparent)] pub struct RootId(pub u64); /// Identifies an image within a catalog. @@ -26,7 +27,8 @@ pub struct ImageId(pub u64); pub struct VersionId(pub u64); /// Identifies a user-defined collection. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] +#[serde(transparent)] pub struct CollectionId(pub u64); /// Identifies a folder within a root. @@ -244,7 +246,7 @@ impl FormatFilter { /// /// Surfaced in the UI so a user always knows what they have — the failure /// Lightroom makes by showing an original's filename beside a 2560px proxy. -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] pub enum Availability { /// Catalogued, nothing cached. MetadataOnly, diff --git a/core/dr-types/src/selector.rs b/core/dr-types/src/selector.rs index 4cd14fe..9f6a5c7 100644 --- a/core/dr-types/src/selector.rs +++ b/core/dr-types/src/selector.rs @@ -20,7 +20,7 @@ use crate::{Availability, CollectionId, RootId}; /// Compiles to indexed SQL in `dr-catalog`; evaluated against catalog state /// for cache rules. Deliberately data — no closures, so it serialises into a /// saved collection or a sync'd cache rule. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub enum Selector { /// Everything. The empty filter, and the implicit default cache rule. All, @@ -103,7 +103,7 @@ impl Selector { } /// A date constraint, absolute or moving. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub enum DateSelector { /// UTC seconds, half-open: `from <= t < to`. Between { from: i64, to: i64 }, @@ -115,7 +115,7 @@ pub enum DateSelector { } /// Colour labels, matching the conventional set. -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)] pub enum ColourLabel { Red, Yellow, @@ -125,9 +125,17 @@ pub enum ColourLabel { } /// The pick/reject axis, independent of star rating. -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +/// +/// `Unflagged` is the [`Default`] because it is what an image *is* before +/// anyone has looked at it — an unjudged frame, not a rejected one. Any other +/// default would silently assert a judgement the photographer never made. +#[derive( + Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, + serde::Serialize, serde::Deserialize, +)] pub enum FlagState { /// Not yet judged. What "filter to unjudged" selects (FR-CULL-4). + #[default] Unflagged, Pick, Reject, @@ -136,7 +144,7 @@ pub enum FlagState { /// How much of an image a cache rule asks to keep locally. /// /// Ordered so the most generous matching rule wins (ARCH §9.3). -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)] pub enum Tier { /// Catalog rows and sidecars only. Never evicted — authoritative and tiny. Metadata,