From 7ce68cd11516bd7cf037ecea99a92aee7c31b2c3 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 28 Mar 2026 00:47:46 +0800 Subject: Add initial Mingling framework codebase --- mingling/src/asset/node.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 mingling/src/asset/node.rs (limited to 'mingling/src/asset/node.rs') diff --git a/mingling/src/asset/node.rs b/mingling/src/asset/node.rs new file mode 100644 index 0000000..c8b7600 --- /dev/null +++ b/mingling/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(".")) + } +} -- cgit