diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-04-01 20:14:56 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-04-01 20:16:17 +0800 |
| commit | f1ed18e668a830646fe507ee33c4b010a1690342 (patch) | |
| tree | 6d13b5ca65ec4df6b8df1c03df3c96301d435bbf /mingling_core/src/asset | |
| parent | 227e710fe716c8901ee02e670a57fb70eb3f222b (diff) | |
Add documentation for mingling_core
Diffstat (limited to 'mingling_core/src/asset')
| -rw-r--r-- | mingling_core/src/asset/chain.rs | 5 | ||||
| -rw-r--r-- | mingling_core/src/asset/dispatcher.rs | 20 | ||||
| -rw-r--r-- | mingling_core/src/asset/node.rs | 5 | ||||
| -rw-r--r-- | mingling_core/src/asset/renderer.rs | 4 |
4 files changed, 34 insertions, 0 deletions
diff --git a/mingling_core/src/asset/chain.rs b/mingling_core/src/asset/chain.rs index 9f62228..70eda8c 100644 --- a/mingling_core/src/asset/chain.rs +++ b/mingling_core/src/asset/chain.rs @@ -2,12 +2,17 @@ use std::fmt::Display; use crate::ChainProcess; +#[doc(hidden)] pub mod error; +/// Takes over a type (G: Previous) and converts it to another [AnyOutput](./struct.AnyOutput.html) pub trait Chain<G> where G: Display, { + /// The previous type in the chain type Previous; + + /// Process the previous value and return a future that resolves to a [`ChainProcess<G>`](./enum.ChainProcess.html) fn proc(p: Self::Previous) -> impl Future<Output = ChainProcess<G>> + Send; } diff --git a/mingling_core/src/asset/dispatcher.rs b/mingling_core/src/asset/dispatcher.rs index 0863f16..86dfe7c 100644 --- a/mingling_core/src/asset/dispatcher.rs +++ b/mingling_core/src/asset/dispatcher.rs @@ -2,12 +2,22 @@ use std::fmt::Display; use crate::{ChainProcess, Program, asset::node::Node}; +/// Dispatches user input commands to specific [ChainProcess](./enum.ChainProcess.html) +/// +/// Note: If you are using [mingling_macros](https://crates.io/crates/mingling_macros), +/// you can use the `dispatcher!("node.subnode", CommandType => Entry)` macro to declare a `Dispatcher` pub trait Dispatcher<G> where G: Display, { + /// Returns a command node for matching user input fn node(&self) -> Node; + + /// Returns a [ChainProcess](./enum.ChainProcess.html) based on user input arguments, + /// to be sent to the specific invocation fn begin(&self, args: Vec<String>) -> ChainProcess<G>; + + /// Clones the current dispatcher for implementing the `Clone` trait fn clone_dispatcher(&self) -> Box<dyn Dispatcher<G>>; } @@ -39,6 +49,16 @@ impl<C: crate::program::ProgramCollect, G: Display> Program<C, G> { } } +/// A collection of dispatchers. +/// +/// This struct holds a vector of boxed `Dispatcher` trait objects, +/// allowing multiple dispatchers to be grouped together and passed +/// to the program via `Program::with_dispatchers`. +/// A collection of dispatchers. +/// +/// This struct holds a vector of boxed `Dispatcher` trait objects, +/// allowing multiple dispatchers to be grouped together and passed +/// to the program via `Program::with_dispatchers`. pub struct Dispatchers<G> { dispatcher: Vec<Box<dyn Dispatcher<G> + 'static>>, } diff --git a/mingling_core/src/asset/node.rs b/mingling_core/src/asset/node.rs index c8b7600..035d227 100644 --- a/mingling_core/src/asset/node.rs +++ b/mingling_core/src/asset/node.rs @@ -1,11 +1,16 @@ use just_fmt::kebab_case; +/// Represents a command node, used to match user-input command paths. +/// +/// The node consists of multiple parts, each separated by a dot (`.`), and automatically converted to kebab-case. +/// For example, the input string `"node.subnode"` will be converted to a node representation of `["node", "subnode"]`. #[derive(Debug, Default)] pub struct Node { node: Vec<String>, } impl Node { + /// Append a new part to the node path. pub fn join(self, node: impl Into<String>) -> Node { let mut new_node = self.node; new_node.push(node.into()); diff --git a/mingling_core/src/asset/renderer.rs b/mingling_core/src/asset/renderer.rs index 3852b55..de417a2 100644 --- a/mingling_core/src/asset/renderer.rs +++ b/mingling_core/src/asset/renderer.rs @@ -1,6 +1,10 @@ use crate::RenderResult; +/// Takes over a type (Self::Previous) and converts it to a [`RenderResult`](./struct.RenderResult.html) pub trait Renderer { + /// The previous type in the chain type Previous; + + /// Process the previous value and write the result into the provided [`RenderResult`](./struct.RenderResult.html) fn render(p: Self::Previous, r: &mut RenderResult); } |
