diff options
Diffstat (limited to 'src/geom/spec.rs')
| -rw-r--r-- | src/geom/spec.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/geom/spec.rs b/src/geom/spec.rs index 4d631399..3b49b54a 100644 --- a/src/geom/spec.rs +++ b/src/geom/spec.rs @@ -23,6 +23,11 @@ impl<T> Spec<T> { Self { x: v.clone(), y: v } } + /// Borrows the individual fields. + pub fn as_ref(&self) -> Spec<&T> { + Spec { x: &self.x, y: &self.y } + } + /// Maps the individual fields with `f`. pub fn map<F, U>(self, mut f: F) -> Spec<U> where @@ -40,6 +45,14 @@ impl<T> Spec<T> { } } + /// Whether a condition is true for at least one of fields. + pub fn any<F>(self, mut f: F) -> bool + where + F: FnMut(&T) -> bool, + { + f(&self.x) || f(&self.y) + } + /// Whether a condition is true for both fields. pub fn all<F>(self, mut f: F) -> bool where |
