Skip to main content

hydro_lang/live_collections/
mod.rs

1//! Definitions for live collections, which offer the core APIs for writing distributed applications.
2//!
3//! Traditional programs (like those in Rust) typically manipulate **collections** of data elements,
4//! such as those stored in a `Vec` or `HashMap`. These collections are **fixed** in the sense that
5//! any transformations applied to them such as `map` are immediately executed on a snapshot of the
6//! collection. This means that the output will not be updated when the input collection is modified.
7//!
8//! In Hydro, programs instead work with **live collections** which are expected to dynamically
9//! change over time as new elements are added or removed (in response to API requests, streaming
10//! ingestion, etc). Applying a transformation like `map` to a live collection results in another live
11//! collection that will dynamically change over time. All network inputs and outputs in Hydro are
12//! handled via live collections, so the majority of application logic written with Hydro will involve
13//! manipulating live collections.
14//!
15//! See the [Hydro docs](https://hydro.run/docs/hydro/reference/introduction/live-collections) for more.
16
17pub mod boundedness;
18
19pub mod keyed_singleton;
20#[doc(inline)]
21pub use keyed_singleton::KeyedSingleton;
22
23pub mod keyed_stream;
24#[doc(inline)]
25pub use keyed_stream::KeyedStream;
26
27pub mod optional;
28#[doc(inline)]
29pub use optional::Optional;
30
31pub mod singleton;
32#[doc(inline)]
33pub use singleton::Singleton;
34
35pub mod stream;
36#[doc(inline)]
37pub use stream::Stream;
38
39pub mod sliced;
40
41#[doc(hidden)]
42pub mod batch_atomic;
43
44/// Wraps a freshly-created live collection IR node in an `Rc<RefCell<...>>` and registers it
45/// with the flow state, so that the [`crate::compile::builder::FlowBuilder`] can yank the IR
46/// of collections that are still alive when the flow is finalized (see hydro-project/hydro#3051).
47pub(crate) fn tracked_ir_node(
48    flow_state: &crate::compile::builder::FlowState,
49    ir_node: crate::compile::ir::HydroNode,
50) -> std::rc::Rc<std::cell::RefCell<crate::compile::ir::HydroNode>> {
51    let cell = std::rc::Rc::new(std::cell::RefCell::new(ir_node));
52    flow_state
53        .borrow_mut()
54        .live_collection_nodes
55        .push(std::rc::Rc::downgrade(&cell));
56    cell
57}