summaryrefslogtreecommitdiff
path: root/src/model/content.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/content.rs')
-rw-r--r--src/model/content.rs18
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.