id_effect/lib.rs
1//! `Effect<A, E = Never, R = HNil>`: a lazy, `Send` effect over a typed capability list `R`, run
2//! on a fiber runtime (design A, ADR 0011).
3//!
4//! - **[`Effect`]** — the core value: [`succeed`], [`fail`], [`sync`], [`from_async`],
5//! `map` / `flat_map` / `map_err` / `catch`, run at the edge with `Effect::block_on` or awaited
6//! with [`Runtime::run`]. [`LocalEffect`] holds `!Send` values.
7//! - **[`effect!`](macro@effect)** — do-notation over an async body: `~Cap` reads a capability,
8//! `~expr` binds a sub-effect, `~(a, b)` joins in parallel; [`caps!`](macro@caps) spells `R`.
9//! - **Typed `R`** — an HList of capabilities ([`HCons`], [`HNil`], [`need`], `provide`,
10//! `provide_env`), built from [`Layer`]s (`merge`, `provide_to`, scoped layers).
11//! - **Fibers** — `fork` / `join` / interrupt, [`FiberRef`], [`Scope`], [`all`] / `zip_par` /
12//! [`race`], the [`Fabric`] admission scheduler, deterministic [`TestExecutor`].
13//! - **Libraries** — [`Stream`] / [`Sink`], [`Schedule`] (`Effect::retry` / `repeat`),
14//! coordination ([`Queue`], [`Channel`], [`Deferred`], [`Semaphore`], [`PubSub`], [`Ref`], …),
15//! resources ([`Pool`], [`Cache`]), metrics and spans ([`MetricRegistry`], `with_span`),
16//! request batching and caching.
17//! - **Kernel-independent** — [`failure`] (`Cause`, `Exit`, `Defect`, `Or`), [`foundation`]
18//! ([`Pipe`], `pipe!`), [`schema`], [`scheduling`] (`Duration`, `UtcDateTime`), [`match_`].
19//!
20//! ## Cargo features
21//!
22//! - **`compute`** (default) — the Compute Fabric ([`mod@compute`]): admission control, adaptive
23//! Rayon parallelism for bulk operations and `sysinfo` host telemetry. Without it, bulk
24//! operations run serially; `rayon` and `sysinfo` are not built.
25//! - **`schema-serde`** — `serde_json::Value` ↔ [`Unknown`] and JSON Schema helpers.
26//!
27//! Algebraic type classes, persistent (`im`) collections and STM live in the maintenance-tier
28//! `id_effect_fp` crate.
29
30#![forbid(unsafe_code)]
31#![deny(missing_docs)]
32// CI runs `cargo doc` with `RUSTDOCFLAGS=-D warnings`; allow rustdoc lints until intra-doc links are
33// normalized (ambiguous modules, redundant explicit targets, etc.).
34#![allow(rustdoc::all)]
35// `effect-dylint-rules` targets crates that *compose* `Effect` at the edge; this crate implements
36// the runtime (`Effect::block_on`, `Runtime`, …). Lints are crate-allowed here; see
37// `.cursor/skills/effect.rs-fundamentals/SKILL.md` for caller-facing rules.
38#![allow(unknown_lints)]
39#![allow(
40 effect_success_should_be_fn_type_param,
41 effect_no_effect_suffix_on_graph_builder,
42 effect_run_blocking_outside_boundary,
43 effect_run_async_outside_boundary,
44 effect_prefer_from_async_over_new_async,
45 effect_from_async_single_await,
46 effect_effect_generics_need_bounds,
47 effect_multiple_top_level_effect_macros,
48 effect_returning_effect_should_use_effect_macro,
49 effect_no_async_fn_application,
50 clippy::doc_overindented_list_items,
51 clippy::should_implement_trait,
52 clippy::type_complexity,
53 clippy::unnecessary_lazy_evaluations
54)]
55// `#[cfg(test)]` law tests and similar intentionally exercise patterns Clippy flags (`unit` values,
56// `clone` on `Copy` `Result`, etc.); keep `cargo clippy -p id_effect --all-targets -- -D warnings` green.
57#![cfg_attr(
58 test,
59 allow(
60 clippy::bool_assert_comparison,
61 clippy::clone_on_copy,
62 clippy::empty_line_after_doc_comments,
63 clippy::let_unit_value,
64 clippy::map_identity,
65 clippy::redundant_closure,
66 clippy::unit_arg,
67 clippy::unit_cmp,
68 )
69)]
70
71// Lets `::id_effect::…` in macro expansions resolve when those macros are used inside this crate.
72extern crate self as id_effect;
73
74/// Compiles and runs the README quick start as a doctest.
75#[cfg(doctest)]
76#[doc = include_str!("../README.md")]
77struct ReadmeDoctests;
78
79pub use id_effect_macro::{err, pipe};
80pub use id_effect_proc_macro::{
81 EffectData, Optics, ProviderSpec as ProviderSpecDerive, Schema, caps, effect, effect_local,
82 effect_tagged, match_effect,
83};
84
85// ── the 0.7 kernel ──────────────────────────────────────────────────────────────────────────
86// Every module's items are glob re-exported at the root, so item names must be unique across
87// them (`ambiguous_glob_reexports` is denied by clippy `-D warnings`).
88pub mod capability;
89pub mod compute;
90pub mod concurrency;
91pub mod coordination;
92pub mod kernel;
93pub mod layer;
94pub mod observability;
95pub mod par;
96pub mod race;
97pub mod random;
98pub mod request;
99pub mod resource;
100pub mod runtime;
101pub mod scheduling;
102pub mod scope;
103pub mod streaming;
104pub mod testing;
105
106pub use capability::*;
107pub use compute::*;
108pub use concurrency::*;
109pub use coordination::*;
110pub use kernel::*;
111pub use layer::*;
112pub use observability::*;
113pub use par::*;
114pub use race::*;
115pub use random::*;
116pub use request::*;
117pub use resource::*;
118pub use runtime::*;
119pub use scheduling::*;
120pub use scope::*;
121pub use streaming::*;
122pub use testing::*;
123
124#[doc(hidden)]
125pub use kernel::macro_support as __private;
126
127// ── kernel-independent modules ──────────────────────────────────────────────────────────────
128pub mod failure;
129pub mod foundation;
130pub mod macros;
131pub mod match_;
132#[cfg(feature = "compute")]
133pub mod parallelism;
134pub mod schema;
135
136pub use crate::match_::{HasTag, Matcher};
137pub use failure::{Cause, Defect, Exit, FiberId, Never, Or};
138#[doc(inline)]
139pub use foundation::either::Either;
140pub use foundation::func::{always, compose, identity};
141pub use foundation::piping::Pipe;
142pub use foundation::predicate::Predicate;
143pub use schema::brand::Brand;
144pub use schema::data::{DataError, DataStruct, DataTuple, EffectData as EffectDataTrait};
145pub use schema::equal::{EffectHash, Equal};
146pub use schema::order::{DynOrder, Ordering, ordering};
147pub use schema::{HasSchema, ParseError, ParseErrors, Redacted, Schema, Unknown};