diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-26 13:39:18 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-26 13:41:27 +0100 |
| commit | 7af46fc025ee08eb78ae7f6898300083c886bf6f (patch) | |
| tree | 5837d972961844650bc9668d8516d7b5239a8d18 /src/model/content.rs | |
| parent | 3cdd8bfa40fe5fdf0c676af905c3c2c1f614ef24 (diff) | |
Dynamic labels
Diffstat (limited to 'src/model/content.rs')
| -rw-r--r-- | src/model/content.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/model/content.rs b/src/model/content.rs index 0faf76cb..a7161798 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -21,7 +21,7 @@ pub struct Content { obj: Arc<dyn Bounds>, guards: Vec<Guard>, span: Option<Span>, - label: Option<EcoString>, + label: Option<Label>, } impl Content { @@ -54,7 +54,7 @@ impl Content { } /// Attach a label to the content. - pub fn labelled(mut self, label: EcoString) -> Self { + pub fn labelled(mut self, label: Label) -> Self { self.label = Some(label); self } @@ -131,7 +131,7 @@ impl Content { } /// The content's label. - pub fn label(&self) -> Option<&EcoString> { + pub fn label(&self) -> Option<&Label> { self.label.as_ref() } @@ -139,7 +139,7 @@ impl Content { pub fn field(&self, name: &str) -> Option<Value> { if name == "label" { return Some(match &self.label { - Some(label) => Value::Str(label.clone().into()), + Some(label) => Value::Label(label.clone()), None => Value::None, }); } @@ -335,6 +335,16 @@ impl Debug for SequenceNode { } } +/// A label for a node. +#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +pub struct Label(pub EcoString); + +impl Debug for Label { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!(f, "<{}>", self.0) + } +} + /// A constructable, stylable content node. pub trait Node: 'static + Capable { /// Pack a node into type-erased content. |
