From 89f2e71852e96062ea9b756bf92fbf4e894871b1 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 17 Nov 2021 17:09:19 +0100 Subject: Align node --- src/geom/spec.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/geom/spec.rs') 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 Spec { 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(self, mut f: F) -> Spec where @@ -40,6 +45,14 @@ impl Spec { } } + /// Whether a condition is true for at least one of fields. + pub fn any(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(self, mut f: F) -> bool where -- cgit v1.2.3