From 31f904a2c406953cbce334e02b37a712b9b9d016 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 21 Dec 2022 16:19:46 +0100 Subject: Split up and document shapes --- src/model/cast.rs | 16 ++++++------- src/model/styles.rs | 68 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 48 insertions(+), 36 deletions(-) (limited to 'src/model') 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 Cast for Smart { } } -impl Cast for Sides +impl Cast for Sides> 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 { ::error(value) } @@ -452,9 +452,9 @@ where } } -impl Cast for Corners +impl Cast for Corners> 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 { ::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> { - type Output = Axes; +impl Fold for Axes> +where + T: Fold, +{ + type Output = Axes; 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 +impl Fold for Sides> where T: Fold, { type Output = Sides; 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>> { - type Output = Sides>; +impl Fold for Corners> +where + T: Fold, +{ + type Output = Corners; 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>>> { - type Output = Sides>>; +impl Fold for PartialStroke { + 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 Fold for Corners -where - T: Fold, -{ - type Output = Corners; +impl Fold for Rel { + 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>> { - type Output = Corners>; +impl Fold for Rel { + 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 { +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 } } -- cgit v1.2.3