hydro_lang/properties/
mod.rs1use std::marker::PhantomData;
4
5use stageleft::properties::Property;
6
7use crate::live_collections::stream::{ExactlyOnce, Ordering, Retries, TotalOrder};
8
9#[sealed::sealed]
11pub trait CommutativeProof {}
12
13#[sealed::sealed]
15pub trait IdempotentProof {}
16
17pub struct ManualProof();
19#[sealed::sealed]
20impl CommutativeProof for ManualProof {}
21#[sealed::sealed]
22impl IdempotentProof for ManualProof {}
23
24pub enum NotProved {}
26
27pub enum Proved {}
29
30pub struct AggFuncAlgebra<Commutative = NotProved, Idempotent = NotProved>(
48 PhantomData<(Commutative, Idempotent)>,
49);
50impl<C, I> AggFuncAlgebra<C, I> {
51 pub fn commutative(self, _proof: impl CommutativeProof) -> AggFuncAlgebra<Proved, I> {
53 AggFuncAlgebra(PhantomData)
54 }
55
56 pub fn idempotent(self, _proof: impl IdempotentProof) -> AggFuncAlgebra<C, Proved> {
58 AggFuncAlgebra(PhantomData)
59 }
60}
61
62impl<C, I> Property for AggFuncAlgebra<C, I> {
63 type Root = AggFuncAlgebra;
64
65 fn make_root(_target: &mut Option<Self>) -> Self::Root {
66 AggFuncAlgebra(PhantomData)
67 }
68}
69
70#[diagnostic::on_unimplemented(
72 message = "Because the input stream has ordering `{O}`, the closure must demonstrate commutativity with a `commutative = ...` annotation.",
73 label = "required for this call"
74)]
75#[sealed::sealed]
76pub trait ValidCommutativityFor<O: Ordering> {}
77#[sealed::sealed]
78impl ValidCommutativityFor<TotalOrder> for NotProved {}
79#[sealed::sealed]
80impl<O: Ordering> ValidCommutativityFor<O> for Proved {}
81
82#[diagnostic::on_unimplemented(
84 message = "Because the input stream has retries `{R}`, the closure must demonstrate idempotence with an `idempotent = ...` annotation.",
85 label = "required for this call"
86)]
87#[sealed::sealed]
88pub trait ValidIdempotenceFor<R: Retries> {}
89#[sealed::sealed]
90impl ValidIdempotenceFor<ExactlyOnce> for NotProved {}
91#[sealed::sealed]
92impl<R: Retries> ValidIdempotenceFor<R> for Proved {}