diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-12-21 16:19:46 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-12-21 16:19:46 +0100 |
| commit | 31f904a2c406953cbce334e02b37a712b9b9d016 (patch) | |
| tree | c23f6e063864d97afb9b3d58c10ce4c2877106c5 /src | |
| parent | 4af7b9118c5ce612b3d9d7dd06118ce23b731d9c (diff) | |
Split up and document shapes
Diffstat (limited to 'src')
| -rw-r--r-- | src/model/cast.rs | 16 | ||||
| -rw-r--r-- | src/model/styles.rs | 68 |
2 files changed, 48 insertions, 36 deletions
diff --git a/src/model/cast.rs b/src/model/cast.rs index 1a5cae45..17ed2d30 100644 --- a/src/model/cast.rs +++ b/src/model/cast.rs @@ -415,9 +415,9 @@ impl<T: Cast> Cast for Smart<T> { } } -impl<T> Cast for Sides<T> +impl<T> Cast for Sides<Option<T>> where - T: Cast + Default + Copy, + T: Cast + Copy, { fn is(value: &Value) -> bool { matches!(value, Value::Dict(_)) || T::is(value) @@ -439,9 +439,9 @@ where dict.finish(&["left", "top", "right", "bottom", "x", "y", "rest"])?; - Ok(sides.map(Option::unwrap_or_default)) + Ok(sides) } else if T::is(&value) { - Ok(Self::splat(T::cast(value)?)) + Ok(Self::splat(Some(T::cast(value)?))) } else { <Self as Cast>::error(value) } @@ -452,9 +452,9 @@ where } } -impl<T> Cast for Corners<T> +impl<T> Cast for Corners<Option<T>> where - T: Cast + Default + Copy, + T: Cast + Copy, { fn is(value: &Value) -> bool { matches!(value, Value::Dict(_)) || T::is(value) @@ -488,9 +488,9 @@ where "rest", ])?; - Ok(corners.map(Option::unwrap_or_default)) + Ok(corners) } else if T::is(&value) { - Ok(Self::splat(T::cast(value)?)) + Ok(Self::splat(Some(T::cast(value)?))) } else { <Self as Cast>::error(value) } diff --git a/src/model/styles.rs b/src/model/styles.rs index 1eaf5128..e78d83cd 100644 --- a/src/model/styles.rs +++ b/src/model/styles.rs @@ -914,67 +914,79 @@ where } } -impl Fold for Axes<Option<GenAlign>> { - type Output = Axes<GenAlign>; +impl<T> Fold for Axes<Option<T>> +where + T: Fold, +{ + type Output = Axes<T::Output>; fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer).map(|(inner, outer)| inner.unwrap_or(outer)) + self.zip(outer).map(|(inner, outer)| match inner { + Some(value) => value.fold(outer), + None => outer, + }) } } -impl<T> Fold for Sides<T> +impl<T> Fold for Sides<Option<T>> where T: Fold, { type Output = Sides<T::Output>; fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer).map(|(inner, outer)| inner.fold(outer)) + self.zip(outer).map(|(inner, outer)| match inner { + Some(value) => value.fold(outer), + None => outer, + }) } } -impl Fold for Sides<Option<Rel<Abs>>> { - type Output = Sides<Rel<Abs>>; +impl<T> Fold for Corners<Option<T>> +where + T: Fold, +{ + type Output = Corners<T::Output>; fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer).map(|(inner, outer)| inner.unwrap_or(outer)) + self.zip(outer).map(|(inner, outer)| match inner { + Some(value) => value.fold(outer), + None => outer, + }) } } -impl Fold for Sides<Option<Smart<Rel<Length>>>> { - type Output = Sides<Smart<Rel<Length>>>; +impl Fold for PartialStroke<Abs> { + type Output = Self; fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer).map(|(inner, outer)| inner.unwrap_or(outer)) + Self { + paint: self.paint.or(outer.paint), + thickness: self.thickness.or(outer.thickness), + } } } -impl<T> Fold for Corners<T> -where - T: Fold, -{ - type Output = Corners<T::Output>; +impl Fold for Rel<Length> { + type Output = Self; - fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer).map(|(inner, outer)| inner.fold(outer)) + fn fold(self, _: Self::Output) -> Self::Output { + self } } -impl Fold for Corners<Option<Rel<Abs>>> { - type Output = Corners<Rel<Abs>>; +impl Fold for Rel<Abs> { + type Output = Self; - fn fold(self, outer: Self::Output) -> Self::Output { - self.zip(outer).map(|(inner, outer)| inner.unwrap_or(outer)) + fn fold(self, _: Self::Output) -> Self::Output { + self } } -impl Fold for PartialStroke<Abs> { +impl Fold for GenAlign { type Output = Self; - fn fold(self, outer: Self::Output) -> Self::Output { - Self { - paint: self.paint.or(outer.paint), - thickness: self.thickness.or(outer.thickness), - } + fn fold(self, _: Self::Output) -> Self::Output { + self } } |
