screeps_pathfinding/common/
traits.rs1use screeps::{Direction, Position, RoomXY};
2
3pub trait AddDirection {
6 fn checked_add_direction(self, direction: Direction) -> Option<Self>
7 where
8 Self: Sized;
9}
10
11impl AddDirection for RoomXY {
12 fn checked_add_direction(self, direction: Direction) -> Option<Self> {
13 Self::checked_add_direction(self, direction)
14 }
15}
16
17impl AddDirection for Position {
18 fn checked_add_direction(self, direction: Direction) -> Option<Self> {
19 Self::checked_add_direction(self, direction).ok()
20 }
21}
22
23pub trait GetRangeTo {
26 fn get_range_to(self, other: Self) -> u32;
27}
28
29impl GetRangeTo for RoomXY {
30 fn get_range_to(self, other: Self) -> u32 {
31 self.get_range_to(other).into()
32 }
33}
34
35impl GetRangeTo for Position {
36 fn get_range_to(self, other: Self) -> u32 {
37 self.get_range_to(other)
38 }
39}