blob: 7bcf0beddb8ad087f73cd3f48127a08fc8608b32 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/// A type that provides descriptive information for any [`Grouped`](https://docs.rs/mingling/latest/mingling/trait.Grouped.html) type.
///
/// `mingling_core::metadata::Description` is a conventional type provided by the Metadata system,
/// used to attach readable descriptive metadata to each Entry in a program. It can be attached to
/// any type that implements the `Metadata` trait, serving as the human-readable description text
/// for that Entry.
///
/// # Examples
///
/// Create using the `new` method:
///
/// ```
/// # use mingling_core::metadata::Description;
/// let desc = Description::new("This is an example description");
/// ```
///
/// Create using a `From` conversion:
///
/// ```
/// # use mingling_core::metadata::Description;
/// let desc: Description = "This is an example description".into();
/// ```
///
/// Create using a `From<String>` conversion:
///
/// ```
/// # use mingling_core::metadata::Description;
/// let desc: Description = String::from("This is an example description").into();
/// ```
pub struct Description {
desc: String,
}
impl Description {
/// Creates a new `Description` instance.
///
/// # Arguments
///
/// * `desc` - The description text, which can be any type that implements `Into<String>`
/// (such as `&str`, `String`, `&String`, etc.).
///
/// # Returns
///
/// Returns a `Description` instance containing the specified description text.
///
/// # Example
///
/// ```
/// # use mingling_core::metadata::Description;
/// let desc = Description::new("This is an example description");
/// ```
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)
}
}
|