1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Utilities for working with Position and coordinate pairs
use super::Position;

impl Position {
    /// Returns this position's in-room coordinates as a pair of unsigned
    /// integers.
    #[inline]
    pub fn coords(&self) -> (u32, u32) {
        (self.x(), self.y())
    }

    /// Returns this position's in-room coordinates as a pair of signed
    /// integers.
    #[inline]
    pub fn coords_signed(&self) -> (i32, i32) {
        (self.x() as i32, self.y() as i32)
    }
}

// Note: we would usually implement `From<Position> for (u8, u8)`, but this
// implementation is not allowed as it'd be implementing it on a nested type,
// and both the outer type (`(T, T)`), and the inner ones (`u8`) are from an
// external crate.

impl Into<(u8, u8)> for Position {
    #[inline]
    fn into(self) -> (u8, u8) {
        (self.x() as u8, self.y() as u8)
    }
}

impl Into<(u16, u16)> for Position {
    #[inline]
    fn into(self) -> (u16, u16) {
        (self.x() as u16, self.y() as u16)
    }
}

impl Into<(u32, u32)> for Position {
    #[inline]
    fn into(self) -> (u32, u32) {
        (self.x(), self.y())
    }
}

impl Into<(u64, u64)> for Position {
    #[inline]
    fn into(self) -> (u64, u64) {
        (self.x() as u64, self.y() as u64)
    }
}

impl Into<(i8, i8)> for Position {
    #[inline]
    fn into(self) -> (i8, i8) {
        (self.x() as i8, self.y() as i8)
    }
}

impl Into<(i16, i16)> for Position {
    #[inline]
    fn into(self) -> (i16, i16) {
        (self.x() as i16, self.y() as i16)
    }
}

impl Into<(i32, i32)> for Position {
    #[inline]
    fn into(self) -> (i32, i32) {
        (self.x() as i32, self.y() as i32)
    }
}

impl Into<(i64, i64)> for Position {
    #[inline]
    fn into(self) -> (i64, i64) {
        (self.x() as i64, self.y() as i64)
    }
}