Skip to main content

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::KeyedSingletonBound;
7use crate::compile::ir::BoundKind;
8use crate::live_collections::singleton::SingletonBound;
9
10/// A marker trait indicating whether a stream’s length is bounded (finite) or unbounded (potentially infinite).
11///
12/// Implementors of this trait use it to signal the boundedness property of a stream.
13#[sealed]
14pub trait Boundedness:
15    SingletonBound<UnderlyingBound = Self> + KeyedSingletonBound<UnderlyingBound = Self>
16{
17    /// `true` if the bound is [`Bounded`], `false` if it is [`Unbounded`].
18    const BOUNDED: bool;
19
20    /// The [`BoundKind`] corresponding to this type.
21    const BOUND_KIND: BoundKind = if Self::BOUNDED {
22        BoundKind::Bounded
23    } else {
24        BoundKind::Unbounded
25    };
26}
27
28/// Marks the stream as being unbounded, which means that it is not
29/// guaranteed to be complete in finite time.
30pub enum Unbounded {}
31
32#[sealed]
33impl Boundedness for Unbounded {
34    const BOUNDED: bool = false;
35}
36
37/// Marks the stream as being bounded, which means that it is guaranteed
38/// to be complete in finite time.
39pub enum Bounded {}
40
41#[sealed]
42impl Boundedness for Bounded {
43    const BOUNDED: bool = true;
44}
45
46#[sealed]
47#[diagnostic::on_unimplemented(
48    message = "The input collection must be bounded (`Bounded`), but has bound `{Self}`. Strengthen the boundedness upstream or consider a different API.",
49    label = "required here",
50    note = "To intentionally process a non-deterministic snapshot or batch, you may want to use a `sliced!` region. This introduces non-determinism so avoid unless necessary."
51)]
52/// Marker trait that is implemented for the [`Bounded`] boundedness guarantee.
53pub trait IsBounded: Boundedness {}
54
55#[sealed]
56#[diagnostic::do_not_recommend]
57impl IsBounded for Bounded {}