Skip to main content

Crate cordis

Crate cordis 

Source
Expand description

Cordis is a context-based plugin framework with scoped dependency injection, lifecycle-owned effects, events, configuration interception, and structured logging.

This crate is a Rust port of @deepseek-ai/cordis 4.x. The JavaScript implementation relies heavily on proxies, prototype chains, callable objects, and decorators. The Rust API keeps the same runtime model while replacing those language features with explicit, typed methods.

§Quick start

use cordis::{plugin_sync, Context, Inject, PluginOutput};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;

let root = Context::new();
let counter = Arc::new(AtomicUsize::new(0));
let _counter_effect = root.provide_arc("counter", counter.clone()).unwrap();

let greeter = plugin_sync::<(), _>("greeter", Inject::new(["counter"]),
    |ctx, _config| {
        let counter = ctx.require::<AtomicUsize>("counter")?;
        counter.fetch_add(1, Ordering::SeqCst);
        Ok(PluginOutput::default())
    });

let fiber = root.plugin(greeter, ());
fiber.wait().unwrap();
assert_eq!(counter.load(Ordering::SeqCst), 1);
fiber.dispose().unwrap();

Re-exports§

pub use context::Context;
pub use context::ContextMeta;
pub use context::Isolation;
pub use effect::AsyncDisposer;
pub use effect::EffectHandle;
pub use effect::EffectMeta;
pub use error::CordisError;
pub use error::ErrorCode;
pub use error::Result;
pub use error::ValidationError;
pub use error::ValidationIssue;
pub use events::DispatchMode;
pub use events::Event;
pub use events::EventOptions;
pub use events::EventResult;
pub use events::EventValue;
pub use events::EventsService;
pub use events::is_bailed;
pub use fiber::Fiber;
pub use fiber::FiberState;
pub use logger::C16;
pub use logger::C256;
pub use logger::Exporter;
pub use logger::ExporterConfig;
pub use logger::FormatterFn;
pub use logger::LogArg;
pub use logger::Logger;
pub use logger::LoggerIntercept;
pub use logger::LoggerLevel;
pub use logger::LoggerService;
pub use logger::LoggerType;
pub use logger::Message;
pub use logger::color_code;
pub use logger::default_format;
pub use reflect::Accessor;
pub use reflect::Property;
pub use reflect::ReflectService;
pub use reflect::ServiceInfo;
pub use registry::Inject;
pub use registry::IntoPlugin;
pub use registry::Plugin;
pub use registry::PluginHandle;
pub use registry::PluginKey;
pub use registry::PluginOutput;
pub use registry::RegistryService;
pub use registry::RuntimeInfo;
pub use registry::plugin_async;
pub use registry::plugin_sync;
pub use service::Service;
pub use service::service_async;
pub use service::service_sync;
pub use value::Config;
pub use value::Value;

Modules§

context
Root and child contexts tying all Cordis services together.
effect
Lifecycle-owned effects and single-shot asynchronous disposers.
error
Framework errors and configuration validation diagnostics.
events
Disposal-aware event bus and Cordis dispatch strategies.
fiber
Plugin fiber lifecycle, dependency epochs, and effect cleanup.
logger
Structured logger facade, bounded buffer, formatting, and exporters.
reflect
Scoped service storage and explicit reflection APIs.
registry
Plugin entrypoints, dependency declarations, and runtime registry.
service
Typed service conventions and helpers.
utils
Runtime-agnostic future execution.
value
Cloneable, dynamically typed values used for services, events, and config.