panopticon_core/lib.rs
1#![warn(missing_docs)]
2//! # panopticon-core
3//!
4//! A typestate pipeline engine with compile-time reference validation,
5//! hooks, and an extension system.
6//!
7//! The public surface is split into two tiers. Pick the one that matches
8//! what you're doing:
9//!
10//! - [`prelude`] — building and running pipelines. Start here if you just
11//! want to declare variables, chain steps, attach built-in hooks, and
12//! read results. This is the import most users want.
13//!
14//! - [`extend`] — writing custom operations, hooks, or extensions, and
15//! tooling that walks compiled pipelines (serialisers, alternative
16//! drivers). Re-exports everything in [`prelude`] and adds the authoring
17//! APIs, error types, typestate markers, and the execution graph.
18//!
19//! ```no_run
20//! use panopticon_core::prelude::*;
21//!
22//! let mut pipe = Pipeline::default();
23//! pipe.var("name", "world")?;
24//! pipe.step::<SetVar>(
25//! "greet",
26//! params!("name" => "greeting", "value" => "hello, world"),
27//! )?;
28//! let complete = pipe.compile()?.run().wait()?;
29//! # Ok::<(), Box<dyn std::error::Error>>(())
30//! ```
31
32mod data;
33mod error;
34mod execution;
35mod extensions;
36mod hooks;
37mod operation;
38mod param;
39mod state;
40
41pub mod prelude {
42 //! Everything needed to build and run a pipeline.
43 //!
44 //! Start here for declaring variables, chaining steps, attaching built-in
45 //! hooks, and reading results. For authoring custom operations, hooks, or
46 //! extensions, use [`crate::extend`] instead.
47 //!
48 //! # Reading order
49 //!
50 //! The items below are listed in the order a reader typically encounters
51 //! them when building a pipeline from scratch.
52 //!
53 //! **Pipeline construction** — [`Pipeline`], [`Param`], [`params!`],
54 //! [`GuardSource`], [`IterSource`].
55 //!
56 //! **Collection handles** — [`ArrayHandle`], [`MapHandle`].
57 //!
58 //! **Store and values** — [`Store`], [`StoreEntry`], [`Type`], [`Value`],
59 //! `DeserializeError` (requires the `serde` feature).
60 //!
61 //! **Built-in hooks** — [`EventKind`], [`EventLog`], [`EventRecord`],
62 //! [`Logger`], [`Profiler`], [`StepFilter`], [`StoreValidator`], [`Timeout`].
63 //!
64 //! **Built-in operations** — [`SetVar`], [`Get`], [`Coerce`], [`Compare`],
65 //! [`Dedupe`], [`Len`].
66
67 // Pipeline construction.
68 pub use crate::execution::{GuardSource, IterSource};
69 pub use crate::param::Param;
70 pub use crate::params;
71 pub use crate::state::Pipeline;
72
73 // Handles returned by `Pipeline::array` / `Pipeline::map`.
74 pub use crate::data::{ArrayHandle, MapHandle};
75
76 // Data types exposed when inspecting results or populating a `Store`
77 // through `with_array` / `with_map` closures.
78 pub use crate::data::{Store, StoreEntry, Type, Value};
79
80 #[cfg(feature = "serde")]
81 pub use crate::data::DeserializeError;
82
83 // Built-in hooks.
84 pub use crate::hooks::core::{
85 EventKind, EventLog, EventRecord, Logger, Profiler, StepFilter, StoreValidator, Timeout,
86 };
87
88 // Built-in operations.
89 pub use crate::operation::core::{Coerce, Compare, Dedupe, Get, Len, SetVar};
90}
91
92pub mod extend {
93 //! Authoring surface for custom operations, hooks, extensions, and tooling
94 //! that walks compiled pipelines.
95 //!
96 //! Re-exports everything in [`crate::prelude`] and adds the types needed
97 //! to author new pipeline components or to introspect a compiled pipeline
98 //! (for serialisers, alternative drivers, and similar tooling).
99 //!
100 //! # Reading order
101 //!
102 //! The items below are listed in the order a reader typically encounters
103 //! them when extending the crate. Prelude re-exports are omitted.
104 //!
105 //! **Error types** — [`DraftError`], [`OperationError`], [`AccessError`],
106 //! [`StoreError`], [`op_error!`].
107 //!
108 //! **Operation authoring** — [`Operation`], [`Context`], [`OperationMetadata`],
109 //! [`InputSpec`], [`OutputSpec`], [`NameSpec`], [`OutputScope`],
110 //! [`ExtensionSpec`], [`Parameters`], [`Registry`].
111 //!
112 //! **Hook authoring** — [`Hook`], [`HookEvent`], [`HookAction`].
113 //!
114 //! **Iteration context** — [`IterContext`], [`IterIndex`], [`ITER_INDEX`],
115 //! [`ITER_ITEM`], [`ITER_KEY`], [`ITER_VALUE`].
116 //!
117 //! **Extensions** — [`Extension`].
118 //!
119 //! **Typestates and execution graph** — [`Draft`], [`Ready`], [`Running`],
120 //! [`RunningStatus`], [`Complete`], [`ExecutionNode`].
121
122 pub use crate::prelude::*;
123
124 // Error types.
125 pub use crate::error::{AccessError, DraftError, OperationError, StoreError};
126
127 // Operation authoring.
128 pub use crate::op_error;
129 pub use crate::operation::{
130 Context, ExtensionSpec, InputSpec, NameSpec, Operation, OperationMetadata, OutputScope,
131 OutputSpec, Registry,
132 };
133 pub use crate::param::Parameters;
134
135 // Hook authoring.
136 pub use crate::execution::{IterContext, IterIndex};
137 pub use crate::execution::{ITER_INDEX, ITER_ITEM, ITER_KEY, ITER_VALUE};
138 pub use crate::hooks::{Hook, HookAction, HookEvent};
139
140 // Extension authoring.
141 pub use crate::extensions::Extension;
142
143 // Typestate markers and execution graph — for tooling that walks or
144 // transforms a compiled pipeline.
145 pub use crate::execution::ExecutionNode;
146 pub use crate::state::{Complete, Draft, Ready, Running, RunningStatus};
147}
148
149/// Crate-internal prelude. Gathers the names used across modules so each
150/// file can `use crate::imports::*;` once instead of maintaining a per-file
151/// import list. Some re-exports (built-in ops, built-in hooks, the `params!`
152/// macro) are only touched by in-module tests, so the `allow(unused_imports)`
153/// suppresses false positives in non-test builds. Not part of the public API.
154#[allow(unused_imports)]
155pub(crate) mod imports {
156 pub use crate::data::*;
157 pub use crate::error::*;
158 pub use crate::execution::*;
159 pub use crate::extensions::{Extension, Extensions};
160 pub use crate::hooks::core::*;
161 pub use crate::hooks::{Hook, HookAction, HookEvent};
162 pub(crate) use crate::hooks::emit_all;
163 pub use crate::operation::core::*;
164 pub use crate::op_error;
165 pub use crate::operation::*;
166 pub use crate::param::*;
167 pub use crate::params;
168 pub use crate::state::*;
169
170 pub use std::any::TypeId;
171 pub use std::collections::HashMap;
172 pub use std::sync::{Arc, Mutex, atomic::AtomicBool};
173 pub use std::thread;
174}