Skip to main content

cordis/
lib.rs

1//! Cordis is a context-based plugin framework with scoped dependency injection,
2//! lifecycle-owned effects, events, configuration interception, and structured
3//! logging.
4//!
5//! This crate is a Rust port of `@deepseek-ai/cordis` 4.x.  The JavaScript
6//! implementation relies heavily on proxies, prototype chains, callable
7//! objects, and decorators.  The Rust API keeps the same runtime model while
8//! replacing those language features with explicit, typed methods.
9//!
10//! # Quick start
11//!
12//! ```
13//! use cordis::{plugin_sync, Context, Inject, PluginOutput};
14//! use std::sync::atomic::{AtomicUsize, Ordering};
15//! use std::sync::Arc;
16//!
17//! let root = Context::new();
18//! let counter = Arc::new(AtomicUsize::new(0));
19//! let _counter_effect = root.provide_arc("counter", counter.clone()).unwrap();
20//!
21//! let greeter = plugin_sync::<(), _>("greeter", Inject::new(["counter"]),
22//!     |ctx, _config| {
23//!         let counter = ctx.require::<AtomicUsize>("counter")?;
24//!         counter.fetch_add(1, Ordering::SeqCst);
25//!         Ok(PluginOutput::default())
26//!     });
27//!
28//! let fiber = root.plugin(greeter, ());
29//! fiber.wait().unwrap();
30//! assert_eq!(counter.load(Ordering::SeqCst), 1);
31//! fiber.dispose().unwrap();
32//! ```
33
34#![forbid(unsafe_code)]
35#![warn(missing_docs)]
36
37pub mod context;
38pub mod effect;
39pub mod error;
40pub mod events;
41pub mod fiber;
42pub mod logger;
43pub mod reflect;
44pub mod registry;
45pub mod service;
46pub mod utils;
47pub mod value;
48
49pub use context::{Context, ContextMeta, Isolation};
50pub use effect::{AsyncDisposer, EffectHandle, EffectMeta};
51pub use error::{CordisError, ErrorCode, Result, ValidationError, ValidationIssue};
52pub use events::{
53    DispatchMode, Event, EventOptions, EventResult, EventValue, EventsService, is_bailed,
54};
55pub use fiber::{Fiber, FiberState};
56pub use logger::{
57    C16, C256, Exporter, ExporterConfig, FormatterFn, LogArg, Logger, LoggerIntercept, LoggerLevel,
58    LoggerService, LoggerType, Message, color_code, default_format,
59};
60pub use reflect::{Accessor, Property, ReflectService, ServiceInfo};
61pub use registry::{
62    Inject, IntoPlugin, Plugin, PluginHandle, PluginKey, PluginOutput, RegistryService,
63    RuntimeInfo, plugin_async, plugin_sync,
64};
65pub use service::{Service, service_async, service_sync};
66pub use value::{Config, Value};