Skip to main content

cordis_group/
lib.rs

1//! Nested plugin groups with cascading disable for
2//! [cordis-rs](https://crates.io/crates/cordis-rs).
3//!
4//! A group is an entry with a `group` array in the config file (see
5//! `cordis-include`). At runtime the loader starts each group entry as a
6//! [`Group`] fiber and starts the child entries *beneath that fiber's
7//! context*: disposing the group fiber cascades to the whole subtree, and a
8//! `disabled` flag anywhere on the ancestor chain keeps the subtree from
9//! starting at all (the include tree's `enabled()` walk).
10//!
11//! The plugin itself is deliberately a no-op nesting marker — upstream
12//! cordis' `plugin-group` is similarly tiny. All orchestration lives in
13//! `cordis-loader`, which registers [`GROUP_NAME`] in its builtin registry.
14
15#![forbid(unsafe_code)]
16#![warn(missing_docs)]
17
18use cordis::utils::BoxFuture;
19use cordis::{Config, Context, Plugin, PluginHandle, PluginOutput, Result};
20
21/// Entry name that marks a group (`name: group` in the config file).
22pub const GROUP_NAME: &str = "group";
23
24/// Nesting marker plugin for group entries.
25///
26/// Starting a group produces an active fiber whose context scopes the
27/// subtree's fibers and effects; the loader is the intended driver.
28#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
29pub struct Group;
30
31impl Group {
32    /// A fresh handle around a [`Group`] plugin.
33    ///
34    /// Each call yields a distinct [`cordis::PluginKey`] identity, matching
35    /// one handle per entry.
36    pub fn handle() -> PluginHandle {
37        PluginHandle::new(Group)
38    }
39}
40
41impl Plugin for Group {
42    fn name(&self) -> &str {
43        GROUP_NAME
44    }
45
46    fn apply(&self, _ctx: Context, _config: Config) -> BoxFuture<Result<PluginOutput>> {
47        Box::pin(async { Ok(PluginOutput::default()) })
48    }
49}