summaryrefslogtreecommitdiff
path: root/mingling_core/src/asset
diff options
context:
space:
mode:
Diffstat (limited to 'mingling_core/src/asset')
-rw-r--r--mingling_core/src/asset/chain.rs5
-rw-r--r--mingling_core/src/asset/dispatcher.rs20
-rw-r--r--mingling_core/src/asset/node.rs5
-rw-r--r--mingling_core/src/asset/renderer.rs4
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);
}