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
84#[cfg(any(
85    feature = "deploy",
86    feature = "deploy_integration" // hidden internal feature enabled in the trybuild
87))]
88#[cfg_attr(docsrs, doc(cfg(feature = "deploy")))]
89pub mod deploy;
90
91#[cfg(feature = "sim")]
92#[cfg_attr(docsrs, doc(cfg(feature = "sim")))]
93pub mod sim;
94
95pub mod forward_handle;
96
97pub mod compile;
98
99mod manual_expr;
100
101#[cfg(feature = "viz")]
102#[cfg_attr(docsrs, doc(cfg(feature = "viz")))]
103#[expect(missing_docs, reason = "TODO")]
104pub mod viz;
105
106mod staging_util;
107
108#[cfg(feature = "deploy")]
109#[cfg_attr(docsrs, doc(cfg(feature = "deploy")))]
110pub mod test_util;
111
112#[cfg(feature = "build")]
113#[ctor::ctor]
114fn init_rewrites() {
115    stageleft::add_private_reexport(
116        vec!["tokio_util", "codec", "lines_codec"],
117        vec!["tokio_util", "codec"],
118    );
119}
120
121#[cfg(all(test, feature = "trybuild"))]
122mod test_init {
123    #[ctor::ctor]
124    fn init() {
125        crate::compile::init_test();
126    }
127}