Struct screeps::local::RoomCoordinate
source · pub struct RoomCoordinate(/* private fields */);
Expand description
An X or Y coordinate in a room, restricted to the valid range of coordinates.
Implementations§
source§impl RoomCoordinate
impl RoomCoordinate
sourcepub const fn new(coord: u8) -> Result<Self, OutOfBoundsError>
pub const fn new(coord: u8) -> Result<Self, OutOfBoundsError>
Create a RoomCoordinate
from a u8
, returning an error if the
coordinate is not in the valid room size range
sourcepub unsafe fn unchecked_new(coord: u8) -> Self
pub unsafe fn unchecked_new(coord: u8) -> Self
Create a RoomCoordinate
from a u8
, without checking whether it’s in
the range of valid values.
Safety
Calling this method with coord >= ROOM_SIZE
can result in undefined
behaviour when the resulting RoomCoordinate
is used.
sourcepub fn checked_add(self, rhs: i8) -> Option<RoomCoordinate>
pub fn checked_add(self, rhs: i8) -> Option<RoomCoordinate>
Get the coordinate adjusted by a certain value, returning None
if the
result is outside the valid range.
Example usage:
use screeps::local::RoomCoordinate;
let zero = RoomCoordinate::new(0).unwrap();
let forty_nine = RoomCoordinate::new(49).unwrap();
assert_eq!(zero.checked_add(1), Some(RoomCoordinate::new(1).unwrap()));
assert_eq!(zero.checked_add(-1), None);
assert_eq!(zero.checked_add(49), Some(forty_nine));
assert_eq!(forty_nine.checked_add(1), None);
sourcepub fn saturating_add(self, rhs: i8) -> RoomCoordinate
pub fn saturating_add(self, rhs: i8) -> RoomCoordinate
Get the coordinate adjusted by a certain value, saturating at the edges of the room if the result would be outside of the valid range.
Example usage:
use screeps::local::RoomCoordinate;
let zero = RoomCoordinate::new(0).unwrap();
let forty_nine = RoomCoordinate::new(49).unwrap();
assert_eq!(zero.saturating_add(1), RoomCoordinate::new(1).unwrap());
assert_eq!(zero.saturating_add(-1), zero);
assert_eq!(zero.saturating_add(i8::MAX), forty_nine);
assert_eq!(forty_nine.saturating_add(1), forty_nine);
assert_eq!(forty_nine.saturating_add(i8::MIN), zero);
Trait Implementations§
source§impl Clone for RoomCoordinate
impl Clone for RoomCoordinate
source§fn clone(&self) -> RoomCoordinate
fn clone(&self) -> RoomCoordinate
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for RoomCoordinate
impl Debug for RoomCoordinate
source§impl Default for RoomCoordinate
impl Default for RoomCoordinate
source§fn default() -> RoomCoordinate
fn default() -> RoomCoordinate
Returns the “default value” for a type. Read more
source§impl<'de> Deserialize<'de> for RoomCoordinate
impl<'de> Deserialize<'de> for RoomCoordinate
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>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Display for RoomCoordinate
impl Display for RoomCoordinate
source§impl From<RoomCoordinate> for u8
impl From<RoomCoordinate> for u8
source§fn from(coord: RoomCoordinate) -> u8
fn from(coord: RoomCoordinate) -> u8
Converts to this type from the input type.
source§impl Hash for RoomCoordinate
impl Hash for RoomCoordinate
source§impl Ord for RoomCoordinate
impl Ord for RoomCoordinate
source§fn cmp(&self, other: &RoomCoordinate) -> Ordering
fn cmp(&self, other: &RoomCoordinate) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for RoomCoordinate
impl PartialEq for RoomCoordinate
source§fn eq(&self, other: &RoomCoordinate) -> bool
fn eq(&self, other: &RoomCoordinate) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for RoomCoordinate
impl PartialOrd for RoomCoordinate
source§fn partial_cmp(&self, other: &RoomCoordinate) -> Option<Ordering>
fn partial_cmp(&self, other: &RoomCoordinate) -> Option<Ordering>
1.0.0 · source§fn 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 moresource§impl Serialize for RoomCoordinate
impl Serialize for RoomCoordinate
source§impl TryFrom<u8> for RoomCoordinate
impl TryFrom<u8> for RoomCoordinate
impl Copy for RoomCoordinate
impl Eq for RoomCoordinate
impl StructuralEq for RoomCoordinate
impl StructuralPartialEq for RoomCoordinate
Auto Trait Implementations§
impl RefUnwindSafe for RoomCoordinate
impl Send for RoomCoordinate
impl Sync for RoomCoordinate
impl Unpin for RoomCoordinate
impl UnwindSafe for RoomCoordinate
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more