diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-08 17:08:30 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-09 12:02:35 +0200 |
| commit | 29eb13ca6214461a4b0deb63d589cd39ad6d41c2 (patch) | |
| tree | c86797d440cfcc801c87a3c64f479e39f2c068b1 /src/eval/styles.rs | |
| parent | 712c00ecb72b67da2c0788e5d3eb4dcc6366b2a7 (diff) | |
Sum color and length into stroke
Diffstat (limited to 'src/eval/styles.rs')
| -rw-r--r-- | src/eval/styles.rs | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/src/eval/styles.rs b/src/eval/styles.rs index 575518f5..71293f40 100644 --- a/src/eval/styles.rs +++ b/src/eval/styles.rs @@ -287,15 +287,6 @@ pub trait Key<'a>: 'static { ) -> Self::Output; } -/// A property that is folded to determine its final value. -pub trait Fold { - /// The type of the folded output. - type Output; - - /// Fold this inner value with an outer folded value. - fn fold(self, outer: Self::Output) -> Self::Output; -} - /// A property that is resolved with other properties from the style chain. pub trait Resolve { /// The type of the resolved output. @@ -354,6 +345,39 @@ where } } +/// A property that is folded to determine its final value. +pub trait Fold { + /// The type of the folded output. + type Output; + + /// Fold this inner value with an outer folded value. + fn fold(self, outer: Self::Output) -> Self::Output; +} + +impl<T> Fold for Option<T> +where + T: Fold, + T::Output: Default, +{ + type Output = Option<T::Output>; + + fn fold(self, outer: Self::Output) -> Self::Output { + self.map(|inner| inner.fold(outer.unwrap_or_default())) + } +} + +impl<T> Fold for Smart<T> +where + T: Fold, + T::Output: Default, +{ + type Output = Smart<T::Output>; + + fn fold(self, outer: Self::Output) -> Self::Output { + self.map(|inner| inner.fold(outer.unwrap_or_default())) + } +} + /// A show rule recipe. #[derive(Clone, PartialEq, Hash)] struct Recipe { @@ -472,7 +496,7 @@ impl<'a> StyleChain<'a> { /// Get the output value of a style property. /// /// Returns the property's default value if no map in the chain contains an - /// entry for it. Also takes care of folding and resolving and returns + /// entry for it. Also takes care of resolving and folding and returns /// references where applicable. pub fn get<K: Key<'a>>(self, key: K) -> K::Output { K::get(self, self.values(key)) |
