From b724ba6eacec78b0caa80a7730752b7158742472 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 2 Apr 2021 22:15:57 +0100 Subject: [PATCH] geometry: Promote PosPromote to a trait And provide for f64 Signed-off-by: Ian Jackson --- base/geometry.rs | 7 +++++-- base/prelude.rs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/base/geometry.rs b/base/geometry.rs index df523f79..4040207d 100644 --- a/base/geometry.rs +++ b/base/geometry.rs @@ -87,8 +87,11 @@ impl Mean for i32 { fn mean(&self, other: &Self) -> Self { //---------- Pos ---------- -impl PosC { - pub fn promote(&self) -> PosC { self.map(|v| v as f64) } +pub trait PosPromote { + fn promote(&self) -> PosC; +} +impl PosPromote for PosC where T: Into + Copy + Debug { + fn promote(&self) -> PosC { self.map(|v| v.into()) } } #[derive(Error,Debug,Copy,Clone,Serialize,Deserialize)] diff --git a/base/prelude.rs b/base/prelude.rs index 092409b0..8348fdfd 100644 --- a/base/prelude.rs +++ b/base/prelude.rs @@ -28,7 +28,7 @@ pub use void::Void; pub use crate::html::*; -pub use crate::geometry::{CoordinateOverflow, PosC}; +pub use crate::geometry::{CoordinateOverflow, PosC, PosPromote}; pub use crate::{hformat, hformat_as_display, hwrite}; pub use crate::misc::default; pub use crate::misc::display_as_debug; -- 2.30.2