Struct screeps::local::RoomName

source ·
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.

RoomNames 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

source

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]+. 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.

source

pub const fn x_coord(&self) -> i32

Gets the x coordinate.

For Wxx rooms, returns -xx - 1. For Exx rooms, returns xx.

source

pub const fn y_coord(&self) -> i32

Gets the y coordinate.

For Nyy rooms, returns -yy - 1. For Syy rooms, returns yy.

source

pub fn checked_add(&self, offset: (i32, i32)) -> Option<RoomName>

Adds an (x, y) pair to this room’s name.

Errors

Returns an error if the coordinates are outside of the valid room name bounds.

For a panicking variant of this function, use the implementation of ops::Add for (i32, i32).

source

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

source§

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.

§

type Output = RoomName

The resulting type after applying the + operator.
source§

impl Clone for RoomName

source§

fn clone(&self) -> RoomName

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for RoomName

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for RoomName

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for RoomName

source§

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 From<&RoomName> for JsString

source§

fn from(name: &RoomName) -> JsString

Converts to this type from the input type.
source§

impl From<&RoomName> for JsValue

source§

fn from(name: &RoomName) -> JsValue

Converts to this type from the input type.
source§

impl From<RoomName> for JsString

source§

fn from(name: RoomName) -> JsString

Converts to this type from the input type.
source§

impl From<RoomName> for JsValue

source§

fn from(name: RoomName) -> JsValue

Converts to this type from the input type.
source§

impl FromStr for RoomName

§

type Err = RoomNameParseError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for RoomName

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl JsCollectionFromValue for RoomName

source§

fn from_value(val: JsValue) -> Self

source§

impl JsCollectionIntoValue for RoomName

source§

impl Ord for RoomName

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<&String> for RoomName

source§

fn eq(&self, other: &&String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<&str> for RoomName

source§

fn eq(&self, other: &&str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RoomName> for &String

source§

fn eq(&self, other: &RoomName) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RoomName> for &str

source§

fn eq(&self, other: &RoomName) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RoomName> for String

source§

fn eq(&self, other: &RoomName) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<RoomName> for str

source§

fn eq(&self, other: &RoomName) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<String> for RoomName

source§

fn eq(&self, other: &String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<str> for RoomName

source§

fn eq(&self, other: &str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for RoomName

source§

fn eq(&self, other: &RoomName) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for RoomName

source§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for RoomName

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Sub<(i32, i32)> for RoomName

source§

fn sub(self, (x, y): (i32, i32)) -> Self

Offsets this room name in the opposite direction from the coordinates.

See the implementation for Add<(i32, i32)>.

Panics

Will panic if the subtraction overflows the boundaries of RoomName.

§

type Output = RoomName

The resulting type after applying the - operator.
source§

impl Sub for RoomName

source§

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.

§

type Output = (i32, i32)

The resulting type after applying the - operator.
source§

impl TryFrom<JsString> for RoomName

§

type Error = <RoomName as FromStr>::Err

The type returned in the event of a conversion error.
source§

fn try_from(val: JsString) -> Result<RoomName, Self::Error>

Performs the conversion.
source§

impl TryFrom<JsValue> for RoomName

§

type Error = RoomNameConversionError

The type returned in the event of a conversion error.
source§

fn try_from(val: JsValue) -> Result<RoomName, Self::Error>

Performs the conversion.
source§

impl Copy for RoomName

source§

impl Eq for RoomName

source§

impl StructuralEq for RoomName

source§

impl StructuralPartialEq for RoomName

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,