From 7a82bfad36b8f6949d96910b38c5c60605f0229f Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 7 Sep 2022 21:09:24 +0400 Subject: [PATCH] Improve Rust geom code --- src/geom.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/geom.rs b/src/geom.rs index a32513c..7ea1418 100644 --- a/src/geom.rs +++ b/src/geom.rs @@ -28,6 +28,24 @@ pub struct WinGeom { border_width: c_int, } +impl From for Position { + fn from(sizes: Sizes) -> Self { + Self::new(sizes.width, sizes.height) + } +} + +impl From for Sizes { + fn from(position: Position) -> Self { + Self::new(position.x, position.y) + } +} + +impl From for WinGeom { + fn from(basic_geom: BasicGeom) -> Self { + Self::new(basic_geom, 0) + } +} + impl Position { pub fn new(x: c_int, y: c_int) -> Self { Self { x, y } @@ -201,6 +219,18 @@ mod tests { assert_eq!(WinGeom::default(), WinGeom::new(Default::default(), 0)); } + #[test] + fn position_into_sizes() { + let sizes: Sizes = Position::new(123, 456).into(); + assert_eq!(sizes, Sizes::new(123, 456)); + } + + #[test] + fn sizes_into_position() { + let position: Position = Sizes::new(123, 456).into(); + assert_eq!(position, Position::new(123, 456)); + } + #[test] fn win_geom_total_position() { let position = Position::new(34, 56);