//! **The one way a photo is handed to the phone** (rule 2; the coordinator's//! decision M-b, ALBUMS CORE 1f): the compiler is the lint.//!//! A [`Mark::Handed`](super::bin::Mark::Handed) carries a [`Seal`], and a//! [`PlatformList`] has private fields: outside this crate neither can be//! made, and inside it only [`free_plan`] makes them (a stored Handed mark is//! decoded, which is the only other way one exists). The app's index supplies//! the facts through [`Store`]; every check at the moment of handing is the//! store's [`Store::verdict`], and only a `Go` is handed.//!//! ```compile_fail//! use cotton_core::albums::{bin::Mark, handing::Seal};//! let _ = Mark::Handed { at_ms: 0, seal: Seal(()) };//! ```//!//! ```compile_fail//! use cotton_core::albums::handing::PlatformList;//! let _ = PlatformList { act: "delete", parts: vec![], act_id: String::new() };//! ```usesuper::bin::{self, Mark};usesuper::Platform;/// The proof a Handed mark was made by [`free_plan`]. Its field is private.#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]pubstructSeal(());implSeal {/// Only for decoding a mark the index stored (serde's default).pub(crate) fn decoded() -> Seal {Seal(()) }}/// What the phone is asked to delete (iPhone) or trash (Android), batch by/// batch. Nothing outside [`free_plan`] can make one.#[derive(Debug)]pubstructPlatformList { act: &'static str, parts: Vec<Vec<String>>, act_id: String,}implPlatformList {/// `delete` (iPhone) or `trash` (Android).pubfn act(&self) -> &'static str {self.act }/// The ids, one system request each.pubfn parts(&self) -> &[Vec<String>] { &self.parts }/// The Delete this list belongs to.pubfn act_id(&self) -> &str { &self.act_id }}/// A photo a Delete planned to hand, not yet decided.#[derive(Debug, Clone)]pubstructWaiting {pub pos: i64,pub id: String,pub why: String,/// A main item (not a RAW or other part of one).pub main: bool,}/// What the store's checks say of a waiting photo at this moment.#[derive(Debug, Clone, PartialEq, Eq)]pubenumVerdict {/// Every check holds: hand it.Go,/// No longer binned, or not present, or a part whose main did not go.Skip,/// Stays in the Bin, not handed, with the reason (edited since he binned/// it; the library not yet read again).Hold(String),/// Kept, with the reason (a copy rule).KeepBack(String),}/// How far a Delete's handing has come.#[derive(Debug)]pubenumListed {/// Handed this many so far; more slices to come.More(usize),/// All decided: the list to ask the phone, or none when nothing went.Done(Option<PlatformList>),}/// The index the handing reads and writes.pubtraitStore {typeError;/// Up to `budget` photos of this Delete still to decide, in order.fn waiting(&mutself, budget: usize) -> Result<Vec<Waiting>, Self::Error>;/// Every check, at this moment.fn verdict(&mutself, w: &Waiting) -> Result<Verdict, Self::Error>;/// Write the Handed mark (made here, nowhere else).fn hand(&mutself, w: &Waiting, mark: Mark) -> Result<(), Self::Error>;/// Record a photo that was not handed, and why.fn decided(&mutself, w: &Waiting, verdict: &Verdict) -> Result<(), Self::Error>;/// After each slice: the ids handed in it.fn slice_done(&mutself, handed: &[String]) -> Result<(), Self::Error>;/// How many are still to decide, and every id this Delete handed so far.fn progress(&mutself) -> Result<(usize, Vec<String>), Self::Error>;/// The Delete is decided: asking the phone (`true`) or over with nothing to ask.fn finish(&mutself, asking: bool) -> Result<(), Self::Error>;}/// Decide up to `budget` photos of a Delete, handing each whose every check/// holds; once all are decided, the one list the phone is asked.pubfn free_plan<S: Store>(store: &mut S, act_id: &str, platform: Platform, now: i64, budget: usize) -> Result<Listed, S::Error> {letmut handed = Vec::new();for w in store.waiting(budget)? {match store.verdict(&w)? {Verdict::Go => { store.hand(&w, Mark::Handed { at_ms: now, seal: Seal(()) })?; handed.push(w.id.clone()); } other => store.decided(&w, &other)?, } } store.slice_done(&handed)?;let (left, all) = store.progress()?;if left > 0 {returnOk(Listed::More(all.len())); }if all.is_empty() { store.finish(false)?;returnOk(Listed::Done(None)); } store.finish(true)?;let act = match platform {Platform::Ios => "delete",Platform::Android => "trash", };Ok(Listed::Done(Some(PlatformList { act, parts: bin::free_batches(platform, &all), act_id: act_id.to_string() })))}