From f1ed18e668a830646fe507ee33c4b010a1690342 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Wed, 1 Apr 2026 20:14:56 +0800 Subject: Add documentation for mingling_core --- mingling_core/src/asset/chain.rs | 5 +++++ mingling_core/src/asset/dispatcher.rs | 20 ++++++++++++++++++++ mingling_core/src/asset/node.rs | 5 +++++ mingling_core/src/asset/renderer.rs | 4 ++++ 4 files changed, 34 insertions(+) (limited to 'mingling_core/src/asset') 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 where G: Display, { + /// The previous type in the chain type Previous; + + /// Process the previous value and return a future that resolves to a [`ChainProcess`](./enum.ChainProcess.html) fn proc(p: Self::Previous) -> impl Future> + 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 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) -> ChainProcess; + + /// Clones the current dispatcher for implementing the `Clone` trait fn clone_dispatcher(&self) -> Box>; } @@ -39,6 +49,16 @@ impl Program { } } +/// 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 { dispatcher: Vec + '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, } impl Node { + /// Append a new part to the node path. pub fn join(self, node: impl Into) -> 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); } -- cgit