From 596e5e2440df2d32f1cf3e052dc633e774edf6ee Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 29 Mar 2026 21:48:23 +0800 Subject: Rename mingling to mingling_core and update dependencies --- mingling_core/src/asset/chain.rs | 8 ++ mingling_core/src/asset/chain/error.rs | 13 +++ mingling_core/src/asset/dispatcher.rs | 195 +++++++++++++++++++++++++++++++++ mingling_core/src/asset/node.rs | 54 +++++++++ mingling_core/src/asset/renderer.rs | 6 + 5 files changed, 276 insertions(+) create mode 100644 mingling_core/src/asset/chain.rs create mode 100644 mingling_core/src/asset/chain/error.rs create mode 100644 mingling_core/src/asset/dispatcher.rs create mode 100644 mingling_core/src/asset/node.rs create mode 100644 mingling_core/src/asset/renderer.rs (limited to 'mingling_core/src/asset') diff --git a/mingling_core/src/asset/chain.rs b/mingling_core/src/asset/chain.rs new file mode 100644 index 0000000..1ea1125 --- /dev/null +++ b/mingling_core/src/asset/chain.rs @@ -0,0 +1,8 @@ +use crate::ChainProcess; + +pub mod error; + +pub trait Chain { + type Previous; + fn proc(p: Self::Previous) -> impl Future + Send; +} diff --git a/mingling_core/src/asset/chain/error.rs b/mingling_core/src/asset/chain/error.rs new file mode 100644 index 0000000..d4da4ac --- /dev/null +++ b/mingling_core/src/asset/chain/error.rs @@ -0,0 +1,13 @@ +use crate::AnyOutput; + +#[derive(thiserror::Error, Debug)] +pub enum ChainProcessError { + #[error("Other error: {0}")] + Other(String), + + #[error("IO error: {0}")] + IO(#[from] std::io::Error), + + #[error("Broken chain")] + Broken(AnyOutput), +} diff --git a/mingling_core/src/asset/dispatcher.rs b/mingling_core/src/asset/dispatcher.rs new file mode 100644 index 0000000..13e35f7 --- /dev/null +++ b/mingling_core/src/asset/dispatcher.rs @@ -0,0 +1,195 @@ +use crate::{ChainProcess, Program, asset::node::Node}; + +pub trait Dispatcher { + fn node(&self) -> Node; + fn begin(&self, args: Vec) -> ChainProcess; + fn clone_dispatcher(&self) -> Box; +} + +impl Clone for Box { + fn clone(&self) -> Self { + self.clone_dispatcher() + } +} + +impl Program { + /// Adds a dispatcher to the program. + pub fn with_dispatcher(&mut self, dispatcher: D) + where + D: Into, + { + let dispatchers = dispatcher.into().dispatcher; + self.dispatcher.extend(dispatchers); + } +} + +pub struct Dispatchers { + dispatcher: Vec>, +} + +impl From for Dispatchers +where + D: Dispatcher + 'static, +{ + fn from(dispatcher: D) -> Self { + Self { + dispatcher: vec![Box::new(dispatcher)], + } + } +} + +impl From>> for Dispatchers { + fn from(dispatcher: Vec>) -> Self { + Self { dispatcher } + } +} + +impl From> for Dispatchers { + fn from(dispatcher: Box) -> Self { + Self { + dispatcher: vec![dispatcher], + } + } +} + +impl From<(D,)> for Dispatchers +where + D: Dispatcher + 'static, +{ + fn from(dispatcher: (D,)) -> Self { + Self { + dispatcher: vec![Box::new(dispatcher.0)], + } + } +} + +impl From<(D1, D2)> for Dispatchers +where + D1: Dispatcher + 'static, + D2: Dispatcher + 'static, +{ + fn from(dispatchers: (D1, D2)) -> Self { + Self { + dispatcher: vec![Box::new(dispatchers.0), Box::new(dispatchers.1)], + } + } +} + +impl From<(D1, D2, D3)> for Dispatchers +where + D1: Dispatcher + 'static, + D2: Dispatcher + 'static, + D3: Dispatcher + 'static, +{ + fn from(dispatchers: (D1, D2, D3)) -> Self { + Self { + dispatcher: vec![ + Box::new(dispatchers.0), + Box::new(dispatchers.1), + Box::new(dispatchers.2), + ], + } + } +} + +impl From<(D1, D2, D3, D4)> for Dispatchers +where + D1: Dispatcher + 'static, + D2: Dispatcher + 'static, + D3: Dispatcher + 'static, + D4: Dispatcher + 'static, +{ + fn from(dispatchers: (D1, D2, D3, D4)) -> Self { + Self { + dispatcher: vec![ + Box::new(dispatchers.0), + Box::new(dispatchers.1), + Box::new(dispatchers.2), + Box::new(dispatchers.3), + ], + } + } +} + +impl From<(D1, D2, D3, D4, D5)> for Dispatchers +where + D1: Dispatcher + 'static, + D2: Dispatcher + 'static, + D3: Dispatcher + 'static, + D4: Dispatcher + 'static, + D5: Dispatcher + 'static, +{ + fn from(dispatchers: (D1, D2, D3, D4, D5)) -> Self { + Self { + dispatcher: vec![ + Box::new(dispatchers.0), + Box::new(dispatchers.1), + Box::new(dispatchers.2), + Box::new(dispatchers.3), + Box::new(dispatchers.4), + ], + } + } +} + +impl From<(D1, D2, D3, D4, D5, D6)> for Dispatchers +where + D1: Dispatcher + 'static, + D2: Dispatcher + 'static, + D3: Dispatcher + 'static, + D4: Dispatcher + 'static, + D5: Dispatcher + 'static, + D6: Dispatcher + 'static, +{ + fn from(dispatchers: (D1, D2, D3, D4, D5, D6)) -> Self { + Self { + dispatcher: vec![ + Box::new(dispatchers.0), + Box::new(dispatchers.1), + Box::new(dispatchers.2), + Box::new(dispatchers.3), + Box::new(dispatchers.4), + Box::new(dispatchers.5), + ], + } + } +} + +impl From<(D1, D2, D3, D4, D5, D6, D7)> for Dispatchers +where + D1: Dispatcher + 'static, + D2: Dispatcher + 'static, + D3: Dispatcher + 'static, + D4: Dispatcher + 'static, + D5: Dispatcher + 'static, + D6: Dispatcher + 'static, + D7: Dispatcher + 'static, +{ + fn from(dispatchers: (D1, D2, D3, D4, D5, D6, D7)) -> Self { + Self { + dispatcher: vec![ + Box::new(dispatchers.0), + Box::new(dispatchers.1), + Box::new(dispatchers.2), + Box::new(dispatchers.3), + Box::new(dispatchers.4), + Box::new(dispatchers.5), + Box::new(dispatchers.6), + ], + } + } +} + +impl std::ops::Deref for Dispatchers { + type Target = Vec>; + + fn deref(&self) -> &Self::Target { + &self.dispatcher + } +} + +impl From for Vec> { + fn from(val: Dispatchers) -> Self { + val.dispatcher + } +} diff --git a/mingling_core/src/asset/node.rs b/mingling_core/src/asset/node.rs new file mode 100644 index 0000000..c8b7600 --- /dev/null +++ b/mingling_core/src/asset/node.rs @@ -0,0 +1,54 @@ +use just_fmt::kebab_case; + +#[derive(Debug, Default)] +pub struct Node { + node: Vec, +} + +impl Node { + pub fn join(self, node: impl Into) -> Node { + let mut new_node = self.node; + new_node.push(node.into()); + Node { node: new_node } + } +} + +impl From<&str> for Node { + fn from(s: &str) -> Self { + let node = s.split('.').map(|part| kebab_case!(part)).collect(); + Node { node } + } +} + +impl From for Node { + fn from(s: String) -> Self { + let node = s.split('.').map(|part| kebab_case!(part)).collect(); + Node { node } + } +} + +impl PartialEq for Node { + fn eq(&self, other: &Self) -> bool { + self.node == other.node + } +} + +impl Eq for Node {} + +impl PartialOrd for Node { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for Node { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.node.cmp(&other.node) + } +} + +impl std::fmt::Display for Node { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.node.join(".")) + } +} diff --git a/mingling_core/src/asset/renderer.rs b/mingling_core/src/asset/renderer.rs new file mode 100644 index 0000000..3852b55 --- /dev/null +++ b/mingling_core/src/asset/renderer.rs @@ -0,0 +1,6 @@ +use crate::RenderResult; + +pub trait Renderer { + type Previous; + fn render(p: Self::Previous, r: &mut RenderResult); +} -- cgit