From bf5edbbbbb75120d065d1c9587ccfa4eed4fdca1 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 25 Nov 2022 10:36:31 +0100 Subject: Tidy up --- src/model/content.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/model/content.rs') diff --git a/src/model/content.rs b/src/model/content.rs index 90df5a4e..0faf76cb 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -9,9 +9,7 @@ use comemo::Tracked; use siphasher::sip128::{Hasher128, SipHasher}; use typst_macros::node; -use super::{ - Args, Key, Property, Recipe, RecipeId, Style, StyleMap, Unlabellable, Value, Vm, -}; +use super::{capability, Args, Guard, Key, Property, Recipe, Style, StyleMap, Value, Vm}; use crate::diag::{SourceResult, StrResult}; use crate::syntax::Span; use crate::util::{EcoString, ReadableTypeId}; @@ -21,7 +19,7 @@ use crate::World; #[derive(Clone, Hash)] pub struct Content { obj: Arc, - guards: Vec, + guards: Vec, span: Option, label: Option, } @@ -69,11 +67,11 @@ impl Content { /// Style this content with a style entry. pub fn styled_with_entry(mut self, style: Style) -> Self { if let Some(styled) = self.to_mut::() { - styled.map.apply(style); + styled.map.apply_one(style); self } else if let Some(styled) = self.to::() { let mut map = styled.map.clone(); - map.apply(style); + map.apply_one(style); StyledNode { sub: styled.sub.clone(), map }.pack() } else { StyledNode { sub: self, map: style.into() }.pack() @@ -87,7 +85,7 @@ impl Content { } if let Some(styled) = self.to_mut::() { - styled.map.apply_map(&styles); + styled.map.apply(styles); return self; } @@ -101,7 +99,7 @@ impl Content { recipe: Recipe, ) -> SourceResult { if recipe.selector.is_none() { - recipe.transform.apply(world, recipe.span, self) + recipe.apply(world, self) } else { Ok(self.styled_with_entry(Style::Recipe(recipe))) } @@ -185,7 +183,7 @@ impl Content { /// Disable a show rule recipe. #[doc(hidden)] - pub fn guarded(mut self, id: RecipeId) -> Self { + pub fn guarded(mut self, id: Guard) -> Self { self.guards.push(id); self } @@ -201,7 +199,7 @@ impl Content { } /// Check whether a show rule recipe is disabled. - pub(super) fn is_guarded(&self, id: RecipeId) -> bool { + pub(super) fn is_guarded(&self, id: Guard) -> bool { self.guards.contains(&id) } @@ -378,12 +376,12 @@ pub trait Node: 'static + Capable { fn field(&self, name: &str) -> Option; } -/// A unique identifier for a node. +/// A unique identifier for a node type. #[derive(Copy, Clone, Eq, PartialEq, Hash)] pub struct NodeId(ReadableTypeId); impl NodeId { - /// The id of the given node. + /// The id of the given node type. pub fn of() -> Self { Self(ReadableTypeId::of::()) } @@ -397,7 +395,8 @@ impl Debug for NodeId { /// A capability a node can have. /// -/// This is implemented by trait objects. +/// Should be implemented by trait objects that are accessible through +/// [`Capable`]. pub trait Capability: 'static {} /// Dynamically access a trait implementation at runtime. @@ -406,3 +405,7 @@ pub unsafe trait Capable { /// if `self` implements the trait. fn vtable(&self, of: TypeId) -> Option<*const ()>; } + +/// Indicates that a node cannot be labelled. +#[capability] +pub trait Unlabellable {} -- cgit v1.2.3