diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-02 14:48:51 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-02 14:48:51 +0100 |
| commit | 56342bd972a13ffe21beaf2b87ab7eb1597704b4 (patch) | |
| tree | 78f9549141e753dde4a938670c54f3fe8695a058 /src/model/fold.rs | |
| parent | 37ac5d966ebaf97ac79c507028cd5b742b510b89 (diff) | |
Move layout traits into library
Diffstat (limited to 'src/model/fold.rs')
| -rw-r--r-- | src/model/fold.rs | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/src/model/fold.rs b/src/model/fold.rs deleted file mode 100644 index bc85be01..00000000 --- a/src/model/fold.rs +++ /dev/null @@ -1,81 +0,0 @@ -use super::Smart; -use crate::geom::{Abs, Corners, Length, Rel, Sides}; - -/// 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())) - } -} - -impl<T> Fold for Sides<T> -where - T: Fold, -{ - type Output = Sides<T::Output>; - - fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer, |inner, outer| inner.fold(outer)) - } -} - -impl Fold for Sides<Option<Rel<Abs>>> { - type Output = Sides<Rel<Abs>>; - - fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer, |inner, outer| inner.unwrap_or(outer)) - } -} - -impl Fold for Sides<Option<Smart<Rel<Length>>>> { - type Output = Sides<Smart<Rel<Length>>>; - - fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer, |inner, outer| inner.unwrap_or(outer)) - } -} - -impl<T> Fold for Corners<T> -where - T: Fold, -{ - type Output = Corners<T::Output>; - - fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer, |inner, outer| inner.fold(outer)) - } -} - -impl Fold for Corners<Option<Rel<Abs>>> { - type Output = Corners<Rel<Abs>>; - - fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer, |inner, outer| inner.unwrap_or(outer)) - } -} |
