Skip to main content

rsynko_manager/
rehearsal.rs

1use crate::*;
2use alux_sdk::trait_algebra;
3use ambassador::delegatable_trait;
4
5/// Specifies the rehearsal mode of one request.
6///
7/// Some requests can state what they would do instead of doing it. A request that cannot states
8/// no mode at all, so a renderer never offers a rehearsal where the meaning does not exist.
9#[delegatable_trait]
10pub trait QueueDryRunAlg: ManagerSorts {
11    /// Turns the rehearsal mode of one request on or off.
12    fn set_queue_dry_run(&mut self, id: Self::Id, dry_run: bool);
13}
14
15/// Specifies rehearsal requests and external observations.
16#[delegatable_trait]
17pub trait RehearsalStateAlg: ManagerSorts {
18    /// Applies one rehearsal observation.
19    fn apply_rehearsal_event(&mut self, id: Self::Id, event: RehearsalObservationOp<Self::Change>);
20}
21
22/// Specifies what a rehearsal stated one request would do.
23pub trait RehearsalViewAlg {
24    /// Represents one change a rehearsal states.
25    type Change;
26
27    /// Observes what rehearsal has stated about this request.
28    fn rehearsal(&self) -> RehearsalState<'_>;
29
30    /// Observes the changes a rehearsal stated, in the order it stated them.
31    fn planned_changes(&self) -> impl Iterator<Item = &Self::Change>;
32}
33
34/// Specifies what one planned change states about itself.
35pub trait PlannedChangeAlg {
36    /// Observes the path the change names, relative to the transferred folder.
37    fn change_path(&self) -> &str;
38    /// Observes what would happen to that path.
39    fn change_kind(&self) -> ChangeKind;
40    /// Observes the byte count the change moves, when the rehearsal stated one.
41    fn change_size(&self) -> Option<u64>;
42}
43
44/// Defines the first-order observation stream of one rehearsal.
45///
46/// An observation is a method, so the reified stream is generated from this vocabulary rather than
47/// written out. An interpreter states what each observation *means* and never restates the shape.
48#[trait_algebra(derive(Clone, Debug, PartialEq, Eq))]
49pub trait RehearsalObservation {
50    /// Represents one change a rehearsal states.
51    type Change;
52
53    /// Denotes that an interpreter started rehearsing the request.
54    fn started(&self);
55
56    /// Supplies everything the rehearsal stated would happen, in its own order.
57    fn reported(&self, changes: Vec<Self::Change>);
58
59    /// Denotes rehearsal failure.
60    fn failed(&self, message: String);
61}
62
63/// Denotes what rehearsal has stated about one request.
64#[derive(Clone, Copy, Debug, PartialEq, Eq)]
65pub enum RehearsalState<'a> {
66    /// Denotes a request no one has rehearsed.
67    Unrehearsed,
68    /// Denotes a rehearsal an interpreter is currently performing.
69    Rehearsing,
70    /// Denotes a rehearsal that stated what would happen.
71    Reported,
72    /// Denotes a rehearsal that failed, and why.
73    Failed(&'a str),
74}
75
76/// Denotes what one rehearsed change would do to a path.
77#[derive(Clone, Copy, Debug, PartialEq, Eq)]
78pub enum ChangeKind {
79    /// Denotes a path the transfer would create.
80    Create,
81    /// Denotes a path the transfer would replace with newer content.
82    Update,
83    /// Denotes a path the transfer would remove.
84    Delete,
85    /// Denotes a path the transfer would leave exactly as it is.
86    Unchanged,
87}
88
89impl ChangeKind {
90    /// States every kind a rehearsal distinguishes, the changes before what stays.
91    pub const REPORTED: [Self; 4] = [Self::Create, Self::Update, Self::Delete, Self::Unchanged];
92
93    /// Observes whether the transfer would alter the path.
94    #[must_use]
95    pub const fn alters(self) -> bool {
96        !matches!(self, Self::Unchanged)
97    }
98}