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    #[cfg(feature = "runtime_mimalloc")]
27    pub use mimalloc;
28}
29
30#[doc(hidden)]
31pub mod macro_support {
32    pub use copy_span;
33}
34
35pub mod prelude {
36    // taken from `tokio`
37    //! A "prelude" for users of the `hydro_lang` crate.
38    //!
39    //! 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:
40    //! ```
41    //! # #![allow(warnings)]
42    //! use hydro_lang::prelude::*;
43    //! ```
44    //!
45    //! The prelude may grow over time as additional items see ubiquitous use.
46
47    pub use stageleft::q;
48
49    pub use crate::compile::builder::FlowBuilder;
50    pub use crate::live_collections::boundedness::{Bounded, Unbounded};
51    pub use crate::live_collections::keyed_singleton::KeyedSingleton;
52    pub use crate::live_collections::keyed_stream::KeyedStream;
53    pub use crate::live_collections::optional::Optional;
54    pub use crate::live_collections::singleton::Singleton;
55    pub use crate::live_collections::sliced::sliced;
56    pub use crate::live_collections::stream::Stream;
57    pub use crate::location::{Cluster, External, Location as _, Process, Tick};
58    pub use crate::nondet::{NonDet, nondet};
59
60    /// A macro to set up a Hydro crate.
61    #[macro_export]
62    macro_rules! setup {
63        () => {
64            stageleft::stageleft_no_entry_crate!();
65
66            #[cfg(test)]
67            mod test_init {
68                #[ctor::ctor]
69                fn init() {
70                    $crate::compile::init_test();
71                }
72            }
73        };
74    }
75}
76
77#[cfg(feature = "dfir_context")]
78#[cfg_attr(docsrs, doc(cfg(feature = "dfir_context")))]
79pub mod runtime_context;
80
81pub mod nondet;
82
83pub mod live_collections;
84
85pub mod location;
86
87#[cfg(any(
88    feature = "deploy",
89    feature = "deploy_integration" // hidden internal feature enabled in the trybuild
90))]
91#[cfg_attr(docsrs, doc(cfg(feature = "deploy")))]
92pub mod deploy;
93
94#[cfg(feature = "sim")]
95#[cfg_attr(docsrs, doc(cfg(feature = "sim")))]
96pub mod sim;
97
98pub mod forward_handle;
99
100pub mod compile;
101
102mod manual_expr;
103
104#[cfg(feature = "viz")]
105#[cfg_attr(docsrs, doc(cfg(feature = "viz")))]
106#[expect(missing_docs, reason = "TODO")]
107pub mod viz;
108
109mod staging_util;
110
111#[cfg(feature = "deploy")]
112#[cfg_attr(docsrs, doc(cfg(feature = "deploy")))]
113pub mod test_util;
114
115#[cfg(feature = "build")]
116#[ctor::ctor]
117fn init_rewrites() {
118    stageleft::add_private_reexport(
119        vec!["tokio_util", "codec", "lines_codec"],
120        vec!["tokio_util", "codec"],
121    );
122}
123
124#[cfg(test)]
125mod test_init {
126    #[ctor::ctor]
127    fn init() {
128        crate::compile::init_test();
129    }
130}