hydro_lang/live_collections/boundedness.rs
1//! Type declarations for boundedness markers, which indicate whether a live collection is finite
2//! and immutable ([`Bounded`]) or asynchronously arriving over time ([`Unbounded`]).
3
4use sealed::sealed;
5
6use super::keyed_singleton::{BoundedValue, KeyedSingletonBound};
7
8/// A marker trait indicating whether a stream’s length is bounded (finite) or unbounded (potentially infinite).
9///
10/// Implementors of this trait use it to signal the boundedness property of a stream.
11#[sealed]
12pub trait Boundedness: KeyedBoundFoldLike {}
13
14/// Marks the stream as being unbounded, which means that it is not
15/// guaranteed to be complete in finite time.
16pub enum Unbounded {}
17
18#[sealed]
19impl Boundedness for Unbounded {}
20
21/// Marks the stream as being bounded, which means that it is guaranteed
22/// to be complete in finite time.
23pub enum Bounded {}
24
25#[sealed]
26impl Boundedness for Bounded {}
27
28/// Helper trait that determines the boundedness for the result of keyed aggregations.
29#[sealed::sealed]
30pub trait KeyedBoundFoldLike {
31 /// The boundedness of the keyed singleton if the values for each key will asynchronously change.
32 type WhenValueUnbounded: KeyedSingletonBound<UnderlyingBound = Self>;
33 /// The boundedness of the keyed singleton if the value for each key is immutable.
34 type WhenValueBounded: KeyedSingletonBound<UnderlyingBound = Self>;
35}
36
37#[sealed::sealed]
38impl KeyedBoundFoldLike for Unbounded {
39 type WhenValueUnbounded = Unbounded;
40 type WhenValueBounded = BoundedValue;
41}
42
43#[sealed::sealed]
44impl KeyedBoundFoldLike for Bounded {
45 type WhenValueUnbounded = Bounded;
46 type WhenValueBounded = Bounded;
47}