[−][src]Struct screeps::memory::MemoryReference
A Reference
to a screeps memory object
Methods
impl MemoryReference
[src]
pub fn new() -> Self
[src]
pub unsafe fn from_reference_unchecked(reference: Reference) -> Self
[src]
Creates a MemoryReference from some JavaScript reference.
Warning: MemoryReference
is only designed to work with "plain"
JavaScript objects, and passing an array or a non-plain object
into this method probably won't be what you want. MemoryReference
also gives access to all properties, so if this is indeed a plain
object, all of its values should also be plain objects.
Passing a non-plain-object reference into this function won't
invoke undefined behavior in and of itself, but other functions
can rely on MemoryReference
being "plain".
pub fn bool(&self, key: &str) -> bool
[src]
pub fn path_bool(&self, path: &str) -> bool
[src]
pub fn f64(&self, key: &str) -> Result<Option<f64>, ConversionError>
[src]
pub fn path_f64(&self, path: &str) -> Result<Option<f64>, ConversionError>
[src]
pub fn i32(&self, key: &str) -> Result<Option<i32>, ConversionError>
[src]
pub fn path_i32(&self, path: &str) -> Result<Option<i32>, ConversionError>
[src]
pub fn string(&self, key: &str) -> Result<Option<String>, ConversionError>
[src]
pub fn path_string(&self, path: &str) -> Result<Option<String>, ConversionError>
[src]
pub fn dict(
&self,
key: &str
) -> Result<Option<MemoryReference>, ConversionError>
[src]
&self,
key: &str
) -> Result<Option<MemoryReference>, ConversionError>
pub fn path_dict(
&self,
path: &str
) -> Result<Option<MemoryReference>, ConversionError>
[src]
&self,
path: &str
) -> Result<Option<MemoryReference>, ConversionError>
pub fn dict_or_create(
&self,
key: &str
) -> Result<MemoryReference, UnexpectedTypeError>
[src]
&self,
key: &str
) -> Result<MemoryReference, UnexpectedTypeError>
Get a dictionary value or create it if it does not exist.
If the value exists but is a different type, this will return None
.
pub fn keys(&self) -> Vec<String>
[src]
pub fn del(&self, key: &str)
[src]
pub fn path_del(&self, path: &str)
[src]
pub fn get<T>(&self, key: &str) -> Result<Option<T>, ConversionError> where
T: TryFrom<Value, Error = ConversionError>,
[src]
T: TryFrom<Value, Error = ConversionError>,
Gets a custom type. Will return None
if null
or undefined
, and
Err
if incorrect type.
Example
use log::info; use screeps::{prelude::*, LocalRoomPosition}; let creep = screeps::game::creeps::get("mycreepname").unwrap(); let mem = creep.memory(); let pos = mem.get::<LocalRoomPosition>("saved_pos").unwrap(); let pos = match pos { Some(pos) => { info!("found position: {}", pos); pos } None => { info!("no position. saving new one!"); let pos = creep.pos().local(); mem.set("saved_pos", pos); pos } }; info!("final position: {}", pos); creep.move_to(&pos);
pub fn get_path<T>(&self, path: &str) -> Result<Option<T>, ConversionError> where
T: TryFrom<Value, Error = ConversionError>,
[src]
T: TryFrom<Value, Error = ConversionError>,
Gets a custom type at a memory path. Will return None
if null
or
undefined
, and Err
if incorrect type.
Uses lodash in JavaScript to evaluate the path. See https://lodash.com/docs/#get.
pub fn set<T>(&self, key: &str, value: T) where
T: JsSerialize,
[src]
T: JsSerialize,
pub fn path_set<T>(&self, path: &str, value: T) where
T: JsSerialize,
[src]
T: JsSerialize,
pub fn arr<T>(&self, key: &str) -> Result<Option<Vec<T>>, ConversionError> where
T: TryFrom<Value, Error = ConversionError>,
[src]
T: TryFrom<Value, Error = ConversionError>,
pub fn path_arr<T>(&self, path: &str) -> Result<Option<Vec<T>>, ConversionError> where
T: TryFrom<Value, Error = ConversionError>,
[src]
T: TryFrom<Value, Error = ConversionError>,
Trait Implementations
impl AsRef<Reference> for MemoryReference
[src]
impl Default for MemoryReference
[src]
impl TryFrom<Value> for MemoryReference
[src]
Auto Trait Implementations
impl Unpin for MemoryReference
impl Sync for MemoryReference
impl Send for MemoryReference
impl RefUnwindSafe for MemoryReference
impl UnwindSafe for MemoryReference
Blanket Implementations
impl<T, U> IntoExpectedType<U> for T where
U: FromExpectedType<T>,
[src]
U: FromExpectedType<T>,
fn into_expected_type(Self) -> Result<U, ConversionError>
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,