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
sourceimpl RoomName
impl RoomName
sourcepub fn new<T>(x: &T) -> Result<Self, RoomNameParseError>where
T: AsRef<str> + ?Sized,
pub fn new<T>(x: &T) -> Result<Self, RoomNameParseError>where
T: AsRef<str> + ?Sized,
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]+
.
sourcepub fn to_array_string(&self) -> ArrayString<[u8; 8]>
pub fn to_array_string(&self) -> ArrayString<[u8; 8]>
Converts this RoomName into an efficient, stack-based string.
This is equivalent to ToString::to_string
, but involves no
allocation.
Trait Implementations
sourceimpl Add<(i32, i32)> for RoomName
impl Add<(i32, i32)> for RoomName
sourcefn 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.
sourceimpl<'de> Deserialize<'de> for RoomName
impl<'de> Deserialize<'de> for RoomName
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Display for RoomName
impl Display for RoomName
sourcefn 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
.
sourceimpl FromStr for RoomName
impl FromStr for RoomName
type Err = RoomNameParseError
type Err = RoomNameParseError
The associated error which can be returned from parsing.
sourceimpl Ord for RoomName
impl Ord for RoomName
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<&String> for RoomName
impl PartialEq<&String> for RoomName
sourceimpl PartialEq<&str> for RoomName
impl PartialEq<&str> for RoomName
sourceimpl PartialEq<RoomName> for &String
impl PartialEq<RoomName> for &String
sourceimpl PartialEq<RoomName> for &str
impl PartialEq<RoomName> for &str
sourceimpl PartialEq<RoomName> for RoomName
impl PartialEq<RoomName> for RoomName
sourceimpl PartialEq<RoomName> for String
impl PartialEq<RoomName> for String
sourceimpl PartialEq<RoomName> for str
impl PartialEq<RoomName> for str
sourceimpl PartialEq<String> for RoomName
impl PartialEq<String> for RoomName
sourceimpl PartialEq<str> for RoomName
impl PartialEq<str> for RoomName
sourceimpl PartialOrd<RoomName> for RoomName
impl PartialOrd<RoomName> for RoomName
sourcefn partial_cmp(&self, other: &RoomName) -> Option<Ordering>
fn partial_cmp(&self, other: &RoomName) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl Sub<(i32, i32)> for RoomName
impl Sub<(i32, i32)> for RoomName
sourceimpl Sub<RoomName> for RoomName
impl Sub<RoomName> for RoomName
sourcefn 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
.
impl Copy for RoomName
impl Eq for RoomName
impl JsSerialize for RoomName
impl StructuralEq for RoomName
impl StructuralPartialEq for RoomName
Auto Trait Implementations
impl RefUnwindSafe for RoomName
impl Send for RoomName
impl Sync for RoomName
impl Unpin for RoomName
impl UnwindSafe for RoomName
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T, U> IntoExpectedType<U> for Twhere
U: FromExpectedType<T>,
impl<T, U> IntoExpectedType<U> for Twhere
U: FromExpectedType<T>,
sourcefn into_expected_type(self) -> Result<U, ConversionError>
fn into_expected_type(self) -> Result<U, ConversionError>
Casts this value as the target type, making the assumption that the types are correct. Read more