diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-07-29 13:21:25 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-07-29 13:28:19 +0200 |
| commit | 2c6127dea611944abb09a0d38375ad7cf9baced0 (patch) | |
| tree | 6572d169d4ce26edc38a880860ebae2f49639fb8 /src/geom | |
| parent | 7d15dc634b3be1b6e284bb6b2450e3736d3e6e8d (diff) | |
Refactor state
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/gen.rs | 10 | ||||
| -rw-r--r-- | src/geom/spec.rs | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/geom/gen.rs b/src/geom/gen.rs index 57dc277d..075b8620 100644 --- a/src/geom/gen.rs +++ b/src/geom/gen.rs @@ -60,6 +60,16 @@ impl Gen<Length> { } } +impl<T> Gen<Option<T>> { + /// Unwrap the individual fields. + pub fn unwrap_or(self, other: Gen<T>) -> Gen<T> { + Gen { + cross: self.cross.unwrap_or(other.cross), + main: self.main.unwrap_or(other.main), + } + } +} + impl<T> Get<GenAxis> for Gen<T> { type Component = T; diff --git a/src/geom/spec.rs b/src/geom/spec.rs index f8f62f9f..ead67f11 100644 --- a/src/geom/spec.rs +++ b/src/geom/spec.rs @@ -75,6 +75,16 @@ impl Spec<Length> { } } +impl<T> Spec<Option<T>> { + /// Unwrap the individual fields. + pub fn unwrap_or(self, other: Spec<T>) -> Spec<T> { + Spec { + horizontal: self.horizontal.unwrap_or(other.horizontal), + vertical: self.vertical.unwrap_or(other.vertical), + } + } +} + impl<T> Get<SpecAxis> for Spec<T> { type Component = T; |
