Cotton code
124 lines · 4.6 KB · RustRaw
//! Cotton Albums, stage 1 (tidy): the rules the phones only draw//! (assets/design/albums/DECISIONS.md, [build-core-decides]).//!//! ```text//! grouping which faces are one person (two stages, cannot-link; never single linkage)//! look     what the core sees in the small grey picture a phone hands it, at//!          whatever size the phone had without the network (Optimise Storage)//! sets     shots of one moment: close in time AND look alike//! picks    best first, then only what looks different, at most six//! tidy     the lists, biggest first, each photo in one list only//! size     bytes: exact where the phone says, "about" where it does not//! bin      Albums' Bin, Free, and what the phone did after Free//! pass     the first pass: what to look at next, at what size, and the//!          honest progress line//! words    every word the screens read//! ```//!//! **Nothing here opens a file, a network or a photo.** A phone reads its own//! library (PhotoKit, MediaStore), hands the core each item's facts//! ([`Item`]) and a small grey picture ([`look::Grey`]); the core answers what//! to show and what a tap means. Photos never leave the phone to be looked at.pub mod bin;pub mod face;pub mod grouping;pub mod handing;pub mod parts;pub mod look;pub mod pass;pub mod picks;pub mod sets;pub mod size;pub mod synthetic;pub mod tidy;pub mod words;#[cfg(test)]mod tests;use serde::{Deserialize, Serialize};/// Which phone's library an item is in. The Bin and Free differ by platform:/// the iPhone gives an app no way back from Recently Deleted, so Albums keeps/// its own Bin until Free; Android's trash can be undone by the app for 30 days.#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]#[serde(rename_all = "snake_case")]pub enum Platform {    Ios,    Android,}impl Platform {    pub const ALL: [Platform; 2] = [Platform::Ios, Platform::Android];}/// Photo or video.#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]#[serde(rename_all = "snake_case")]pub enum Kind {    Photo,    Video,}/// One item of the phone's library, as the phone reads it with no download./// Every field but `id`, `kind` and `taken_at_ms` may be missing.#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]pub struct Item {    /// The platform's own id: PHAsset `localIdentifier` or the MediaStore id.    pub id: String,    pub kind: Kind,    /// When it was taken, milliseconds since 1970 (UTC).    pub taken_at_ms: i64,    #[serde(default)]    pub width: u32,    #[serde(default)]    pub height: u32,    /// Videos: length in milliseconds.    #[serde(default)]    pub duration_ms: u64,    /// Bytes the phone reports (iOS 27 `PHAssetResource.dataSize`, Android    /// `SIZE`); `None` when it does not say, never zero for unknown.    #[serde(default)]    pub bytes: Option<u64>,    /// The phone's own marks: `screenshot`, `screen_recording`, `live`,    /// `burst`, `panorama`, `hdr`, `favourite`, `hidden`, `cloud_shared`, and    /// `trashed` (Android: in the phone's trash; the shell reads trashed items    /// too, so a binned photo is never mistaken for a missing one).    #[serde(default)]    pub flags: Vec<String>,    /// Android `RELATIVE_PATH` or iOS 27 `originalFilename`, for telling a    /// WhatsApp copy; never shown.    #[serde(default)]    pub path: Option<String>,    /// Camera make, when the phone has it without a download.    #[serde(default)]    pub camera: Option<String>,    /// iOS: Apple's cloud identifier, the same on every Apple device on one    /// iCloud library; synced, so his iPad and iPhone agree.    #[serde(default)]    pub cloud_id: Option<String>,    /// The photo's own offset from UTC in seconds where the phone knows it    /// (iOS 27 `extendedMetadata.timeZone`, EXIF `OffsetTimeOriginal`), so a    /// photo taken in Goa reads in Goa's time; `None` falls back to the phone's.    #[serde(default)]    pub offset_s: Option<i64>,    /// Identity (ALBUMS CORE 1f): when the photo joined this library, in    /// milliseconds (Android `DATE_ADDED`); an edit never changes it.    #[serde(default)]    pub added_ms: Option<i64>,    /// Identity: Android `GENERATION_ADDED`, comparable only within one    /// MediaStore version.    #[serde(default)]    pub generation_added: Option<i64>,    /// Content: the library's modification stamp (Android    /// `GENERATION_MODIFIED`, iPhone `modificationDate` in milliseconds).    #[serde(default)]    pub modified: Option<i64>,}impl Item {    pub fn has(&self, flag: &str) -> bool {        self.flags.iter().any(|f| f == flag)    }}