hydro_lang/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![warn(missing_docs)]
3
4//! Hydro is a high-level distributed programming framework for Rust.
5//! Hydro can help you quickly write scalable distributed services that are correct by construction.
6//! Much like Rust helps with memory safety, Hydro helps with [distributed safety](https://hydro.run/docs/hydro/correctness).
7//!
8//! The core Hydro API involves [live collections](https://hydro.run/docs/hydro/live-collections/), which represent asynchronously
9//! updated sources of data such as incoming network requests and application state. The most common live collection is
10//! [`live_collections::stream::Stream`]; other live collections can be found in [`live_collections`].
11//!
12//! Hydro uses a unique compilation approach where you define deployment logic as Rust code alongside your distributed system implementation.
13//! For more details on this API, see the [Hydro docs](https://hydro.run/docs/hydro/deploy/) and the [`deploy`] module.
14
15stageleft::stageleft_no_entry_crate!();
16
17#[cfg(feature = "runtime_support")]
18#[cfg_attr(docsrs, doc(cfg(feature = "runtime_support")))]
19#[doc(hidden)]
20pub mod runtime_support {
21    #[cfg(feature = "sim")]
22    pub use colored;
23    pub use {bincode, dfir_rs, stageleft, tokio};
24    pub mod resource_measurement;
25}
26
27#[doc(hidden)]
28pub mod macro_support {
29    pub use copy_span;
30}
31
32pub mod prelude {
33    // taken from `tokio`
34    //! A "prelude" for users of the `hydro_lang` crate.
35    //!
36    //! This prelude is similar to the standard library's prelude in that you'll almost always want to import its entire contents, but unlike the standard library's prelude you'll have to do so manually:
37    //! ```
38    //! # #![allow(warnings)]
39    //! use hydro_lang::prelude::*;
40    //! ```
41    //!
42    //! The prelude may grow over time as additional items see ubiquitous use.
43
44    pub use stageleft::q;
45
46    pub use crate::compile::builder::FlowBuilder;
47    pub use crate::live_collections::boundedness::{Bounded, Unbounded};
48    pub use crate::live_collections::keyed_singleton::KeyedSingleton;
49    pub use crate::live_collections::keyed_stream::KeyedStream;
50    pub use crate::live_collections::optional::Optional;
51    pub use crate::live_collections::singleton::Singleton;
52    pub use crate::live_collections::sliced::sliced;
53    pub use crate::live_collections::stream::Stream;
54    pub use crate::location::{Cluster, External, Location as _, Process, Tick};
55    pub use crate::nondet::{NonDet, nondet};
56
57    /// A macro to set up a Hydro crate.
58    #[macro_export]
59    macro_rules! setup {
60        () => {
61            stageleft::stageleft_no_entry_crate!();
62
63            #[cfg(test)]
64            mod test_init {
65                #[ctor::ctor]
66                fn init() {
67                    $crate::compile::init_test();
68                }
69            }
70        };
71    }
72}
73
74#[cfg(feature = "dfir_context")]
75#[cfg_attr(docsrs, doc(cfg(feature = "dfir_context")))]
76pub mod runtime_context;
77
78pub mod nondet;
79
80pub mod live_collections;
81
82pub mod location;
83
84pub mod telemetry;
85
86pub mod tests;
87
88#[cfg(any(
89    feature = "deploy",
90    feature = "deploy_integration" // hidden internal feature enabled in the trybuild
91))]
92#[cfg_attr(docsrs, doc(cfg(feature = "deploy")))]
93pub mod deploy;
94
95#[cfg(feature = "sim")]
96#[cfg_attr(docsrs, doc(cfg(feature = "sim")))]
97pub mod sim;
98
99pub mod forward_handle;
100
101pub mod compile;
102
103mod manual_expr;
104
105#[cfg(feature = "viz")]
106#[cfg_attr(docsrs, doc(cfg(feature = "viz")))]
107#[expect(missing_docs, reason = "TODO")]
108pub mod viz;
109
110mod staging_util;
111
112#[cfg(feature = "deploy")]
113#[cfg_attr(docsrs, doc(cfg(feature = "deploy")))]
114pub mod test_util;
115
116#[cfg(feature = "build")]
117#[ctor::ctor]
118fn init_rewrites() {
119    stageleft::add_private_reexport(
120        vec!["tokio_util", "codec", "lines_codec"],
121        vec!["tokio_util", "codec"],
122    );
123}
124
125#[cfg(all(test, feature = "trybuild"))]
126mod test_init {
127    #[ctor::ctor]
128    fn init() {
129        crate::compile::init_test();
130    }
131}