aboutsummaryrefslogtreecommitdiff
path: root/mingling/src
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-04 13:37:19 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-04 13:37:19 +0800
commit26ef5d88f36f69bb856aedc7bb50138933d1e036 (patch)
tree44a73d78f016ac405508df89b80a404b82275ecc /mingling/src
parentb8ccbf380a1253a20303c35a5f3343c4d52e31f5 (diff)
feat(metadata): add Description convention metadata type
Diffstat (limited to 'mingling/src')
-rw-r--r--mingling/src/lib.rs4
-rw-r--r--mingling/src/metadata.rs2
-rw-r--r--mingling/src/metadata/description.rs57
3 files changed, 63 insertions, 0 deletions
diff --git a/mingling/src/lib.rs b/mingling/src/lib.rs
index 01edae9..470c64b 100644
--- a/mingling/src/lib.rs
+++ b/mingling/src/lib.rs
@@ -16,6 +16,10 @@ pub mod CRATE_ROOT {
pub use crate::gen_program::*;
}
+/// Mingling's convention metadatas, which can be bound to types using `#[metadata]`, to provide identification for types
+#[cfg(feature = "core")]
+pub mod metadata;
+
#[cfg(feature = "core")]
mod example_docs;
diff --git a/mingling/src/metadata.rs b/mingling/src/metadata.rs
new file mode 100644
index 0000000..329576c
--- /dev/null
+++ b/mingling/src/metadata.rs
@@ -0,0 +1,2 @@
+mod description;
+pub use description::*;
diff --git a/mingling/src/metadata/description.rs b/mingling/src/metadata/description.rs
new file mode 100644
index 0000000..48bf095
--- /dev/null
+++ b/mingling/src/metadata/description.rs
@@ -0,0 +1,57 @@
+/// Provides a description for any Grouped type.
+pub struct Description {
+ desc: String,
+}
+
+impl Description {
+ /// Creates a new `Description` instance.
+ pub fn new<S: Into<String>>(desc: S) -> Self {
+ Self { desc: desc.into() }
+ }
+}
+
+impl From<String> for Description {
+ fn from(desc: String) -> Self {
+ Self { desc }
+ }
+}
+
+impl From<&str> for Description {
+ fn from(desc: &str) -> Self {
+ Self {
+ desc: desc.to_string(),
+ }
+ }
+}
+
+impl From<Description> for String {
+ fn from(desc: Description) -> Self {
+ desc.desc
+ }
+}
+
+impl From<&Description> for String {
+ fn from(desc: &Description) -> Self {
+ desc.desc.clone()
+ }
+}
+
+impl std::ops::Deref for Description {
+ type Target = str;
+
+ fn deref(&self) -> &Self::Target {
+ &self.desc
+ }
+}
+
+impl std::ops::DerefMut for Description {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.desc
+ }
+}
+
+impl std::fmt::Display for Description {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{}", self.desc)
+ }
+}