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 /// Returns `true` if the bound is [`Bounded`], `false` if it is [`Unbounded`].
14 fn is_bounded() -> bool;
15}
16
17/// Marks the stream as being unbounded, which means that it is not
18/// guaranteed to be complete in finite time.
19pub enum Unbounded {}
20
21#[sealed]
22impl Boundedness for Unbounded {
23 fn is_bounded() -> bool {
24 false
25 }
26}
27
28/// Marks the stream as being bounded, which means that it is guaranteed
29/// to be complete in finite time.
30pub enum Bounded {}
31
32#[sealed]
33impl Boundedness for Bounded {
34 fn is_bounded() -> bool {
35 true
36 }
37}
38
39/// Helper trait that determines the boundedness for the result of keyed aggregations.
40#[sealed::sealed]
41pub trait KeyedBoundFoldLike {
42 /// The boundedness of the keyed singleton if the values for each key will asynchronously change.
43 type WhenValueUnbounded: KeyedSingletonBound<UnderlyingBound = Self>;
44 /// The boundedness of the keyed singleton if the value for each key is immutable.
45 type WhenValueBounded: KeyedSingletonBound<UnderlyingBound = Self>;
46}
47
48#[sealed::sealed]
49impl KeyedBoundFoldLike for Unbounded {
50 type WhenValueUnbounded = Unbounded;
51 type WhenValueBounded = BoundedValue;
52}
53
54#[sealed::sealed]
55impl KeyedBoundFoldLike for Bounded {
56 type WhenValueUnbounded = Bounded;
57 type WhenValueBounded = Bounded;
58}