pub struct RoomName { /* private fields */ }
Expand description
A structure representing a room name.
Ordering
To facilitate use as a key in a BTreeMap
or other similar data
structures, RoomName
implements PartialOrd
and Ord
.
RoomName
s are ordered first by y position, then by x position. North is
considered less than south, and west less than east.
The total ordering is N127W127
, N127W126
, N127W125
, …, N127W0
,
N127E0
, …, N127E127
, N126W127
, …, S127E126
, S127E127
.
This follows left-to-right reading order when looking at the Screeps map from above.
Implementations§
source§impl RoomName
impl RoomName
sourcepub fn new<T>(x: &T) -> Result<Self, RoomNameParseError>
pub fn new<T>(x: &T) -> Result<Self, RoomNameParseError>
Parses a room name from a string.
This will parse the input string, returning an error if it is in an invalid room name.
The expected format can be represented by the regex
[ewEW][0-9]+[nsNS][0-9]+
. If the sim
feature is enabled, sim
is
also valid and uses the packed position of W127N127 (0), matching the
game’s internal implementation of the sim room’s packed positions.
sourcepub const fn x_coord(&self) -> i32
pub const fn x_coord(&self) -> i32
Gets the x coordinate.
For Wxx
rooms, returns -xx - 1
. For Exx
rooms, returns xx
.
sourcepub const fn y_coord(&self) -> i32
pub const fn y_coord(&self) -> i32
Gets the y coordinate.
For Nyy
rooms, returns -yy - 1
. For Syy
rooms, returns yy
.
sourcepub fn to_array_string(&self) -> ArrayString<8>
pub fn to_array_string(&self) -> ArrayString<8>
Converts this RoomName into an efficient, stack-based string.
This is equivalent to ToString::to_string
, but involves no
allocation.
Trait Implementations§
source§impl Add<(i32, i32)> for RoomName
impl Add<(i32, i32)> for RoomName
source§fn add(self, (x, y): (i32, i32)) -> Self
fn add(self, (x, y): (i32, i32)) -> Self
Offsets this room name by a given horizontal and vertical (x, y) pair.
The first number offsets to the west when negative and to the east when positive. The first number offsets to the north when negative and to the south when positive.
Panics
Will panic if the addition overflows the boundaries of RoomName.
source§impl<'de> Deserialize<'de> for RoomName
impl<'de> Deserialize<'de> for RoomName
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl Display for RoomName
impl Display for RoomName
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats this room name into the format the game expects.
Resulting string will be (E|W)[0-9]+(N|S)[0-9]+
, and will result
in the same RoomName if passed into RoomName::new
.
If the sim
feature is enabled, the room corresponding to W127N127
outputs sim
instead.
source§impl JsCollectionFromValue for RoomName
impl JsCollectionFromValue for RoomName
fn from_value(val: JsValue) -> Self
source§impl JsCollectionIntoValue for RoomName
impl JsCollectionIntoValue for RoomName
fn into_value(self) -> JsValue
source§impl Ord for RoomName
impl Ord for RoomName
source§impl PartialEq<&String> for RoomName
impl PartialEq<&String> for RoomName
source§impl PartialEq<&str> for RoomName
impl PartialEq<&str> for RoomName
source§impl PartialEq<RoomName> for &String
impl PartialEq<RoomName> for &String
source§impl PartialEq<RoomName> for &str
impl PartialEq<RoomName> for &str
source§impl PartialEq<RoomName> for String
impl PartialEq<RoomName> for String
source§impl PartialEq<RoomName> for str
impl PartialEq<RoomName> for str
source§impl PartialEq<String> for RoomName
impl PartialEq<String> for RoomName
source§impl PartialEq for RoomName
impl PartialEq for RoomName
source§impl PartialOrd for RoomName
impl PartialOrd for RoomName
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Sub<(i32, i32)> for RoomName
impl Sub<(i32, i32)> for RoomName
source§impl Sub for RoomName
impl Sub for RoomName
source§fn sub(self, other: RoomName) -> (i32, i32)
fn sub(self, other: RoomName) -> (i32, i32)
Subtracts one room name from the other, extracting the difference.
The first return value represents east/west offset, with ‘more east’ being positive and ‘more west’ being negative.
The second return value represents north/south offset, with ‘more south’ being positive and ‘more north’ being negative.
This coordinate system agrees with the implementations Add<(i32, i32)> for RoomName
and Sub<(i32, i32)> for RoomName
.