Skip to main content

oneiros_model/values/
label.rs

1use std::sync::Arc;
2
3#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
4#[serde(transparent)]
5pub struct Label(Arc<str>);
6
7impl Label {
8    pub fn new(label: impl AsRef<str>) -> Self {
9        Self(Arc::from(label.as_ref()))
10    }
11
12    pub fn as_str(&self) -> &str {
13        &self.0
14    }
15}
16
17impl Default for Label {
18    fn default() -> Self {
19        Self(Arc::from(""))
20    }
21}
22
23impl core::fmt::Display for Label {
24    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
25        self.0.fmt(f)
26    }
27}
28
29impl AsRef<str> for Label {
30    fn as_ref(&self) -> &str {
31        self.as_str()
32    }
33}
34
35impl schemars::JsonSchema for Label {
36    fn schema_name() -> std::borrow::Cow<'static, str> {
37        std::borrow::Cow::Borrowed("Label")
38    }
39
40    fn json_schema(_generator: &mut schemars::SchemaGenerator) -> schemars::Schema {
41        schemars::json_schema!({ "type": "string" })
42    }
43}