diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-10 23:23:50 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-10 23:36:36 +0200 |
| commit | 34fa8df044f1491069c9ae69f1c1e73d635c8955 (patch) | |
| tree | 30b9144690f55f0343a1fdbfcac6c9238c617077 /src/eval/styles.rs | |
| parent | 29eb13ca6214461a4b0deb63d589cd39ad6d41c2 (diff) | |
Move language-related properties from `par` to `text`
Closes #67
Diffstat (limited to 'src/eval/styles.rs')
| -rw-r--r-- | src/eval/styles.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/eval/styles.rs b/src/eval/styles.rs index 71293f40..f147d8cf 100644 --- a/src/eval/styles.rs +++ b/src/eval/styles.rs @@ -66,6 +66,14 @@ impl StyleMap { self.0.push(Entry::Recipe(Recipe::new::<T>(func, span))); } + /// Whether the map contains a style property for the given key. + pub fn contains<'a, K: Key<'a>>(&self, _: K) -> bool { + self.0 + .iter() + .filter_map(|entry| entry.property()) + .any(|property| property.key == TypeId::of::<K>()) + } + /// Make `self` the first link of the `tail` chain. /// /// The resulting style chain contains styles from `self` as well as @@ -261,7 +269,7 @@ where /// /// This trait is not intended to be implemented manually, but rather through /// the `#[node]` proc-macro. -pub trait Key<'a>: 'static { +pub trait Key<'a>: Copy + 'static { /// The unfolded type which this property is stored as in a style map. For /// example, this is [`Toggle`](crate::geom::Length) for the /// [`STRONG`](TextNode::STRONG) property. @@ -680,6 +688,15 @@ impl<T> StyleVec<T> { self.items.len() } + /// Iterate over the contained maps. Note that zipping this with `items()` + /// does not yield the same result as calling `iter()` because this method + /// only returns maps once that are shared by consecutive items. This method + /// is designed for use cases where you want to check, for example, whether + /// any of the maps fulfills a specific property. + pub fn maps(&self) -> impl Iterator<Item = &StyleMap> { + self.maps.iter().map(|(map, _)| map) + } + /// Iterate over the contained items. pub fn items(&self) -> std::slice::Iter<'_, T> { self.items.iter() |
