1 //! This module provides a type that represents some location/coordination. 2 //! For example, in WinAPI we have `COORD` which looks and feels inconvenient. 3 //! This module provides also some trait implementations who will make parsing and working with `COORD` easier. 4 5 use winapi::um::wincon::COORD; 6 7 /// This is type represents the position of something on a certain 'x' and 'y'. 8 #[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd)] 9 pub struct Coord { 10 /// the position on the x axis 11 pub x: i16, 12 /// the position on the y axis 13 pub y: i16, 14 } 15 16 impl Coord { 17 /// Create a new coordinate from its x and y position. new(x: i16, y: i16) -> Coord18 pub fn new(x: i16, y: i16) -> Coord { 19 Coord { x, y } 20 } 21 } 22 23 impl From<COORD> for Coord { from(coord: COORD) -> Self24 fn from(coord: COORD) -> Self { 25 Coord::new(coord.X, coord.Y) 26 } 27 } 28 29 impl From<Coord> for COORD { from(location: Coord) -> Self30 fn from(location: Coord) -> Self { 31 COORD { 32 X: location.x, 33 Y: location.y, 34 } 35 } 36 } 37 38 impl Into<(u16, u16)> for Coord { into(self) -> (u16, u16)39 fn into(self) -> (u16, u16) { 40 (self.x as u16, self.y as u16) 41 } 42 } 43