modulink_rs/links/
mod.rs

1//! Link type for modulink-rust
2//! Pure function: async closure, takes Context and returns Context.
3//!
4//! # Shadowing Policy (Ergonomic APIs)
5//! For ergonomic usage (`Link`), always use variable shadowing (e.g., `let ctx = ...`) instead of `mut`.
6//! This prevents accidental mutation and is safer for async/concurrent code. See migration plan for details.
7//!
8//! Example (ergonomic, shadowing):
9//! ```rust
10//! use modulink_rs::context::Context;
11//! let ctx = Context::new();
12//! let ctx = ctx.insert("a", 1);
13//! let ctx = ctx.insert("b", 2);
14//! ```
15//!
16//! Advanced/generic links may use `mut` for performance, but must document the tradeoff.
17
18use crate::context::Context;
19use std::future::Future;
20use std::pin::Pin;
21use std::sync::Arc;
22
23
24/// The generic async link type for any context.
25pub type LinkGeneric<C> = Arc<dyn Fn(C) -> Pin<Box<dyn Future<Output = C> + Send>> + Send + Sync>;
26
27/// The ergonomic link type alias for Context.
28/// For backward compatibility and ergonomic usage, export as Link.
29pub type Link = LinkGeneric<Context>;
30
31// --- Core API Exports ---
32
33
34// Context is re-exported from crate::context
35// Link and LinkErgonomic are defined above
36// Chain, Middleware, Listener will be re-exported from their respective modules
37
38pub use crate::chains::Chain;
39pub use crate::middleware::Middleware;
40
41// Listener system: ergonomic exports for sync and async listeners
42pub use crate::listeners::ListenerSync;
43pub use crate::listeners::ListenerAsync;