Struct screeps::memory::MemoryReference
source · pub struct MemoryReference(_);
Expand description
A Reference
to a screeps memory object
Implementations
sourceimpl MemoryReference
impl MemoryReference
pub fn new() -> Self
sourcepub unsafe fn from_reference_unchecked(reference: Reference) -> Self
pub unsafe fn from_reference_unchecked(reference: Reference) -> Self
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
pub fn path_bool(&self, path: &str) -> bool
pub fn f64(&self, key: &str) -> Result<Option<f64>, ConversionError>
pub fn path_f64(&self, path: &str) -> Result<Option<f64>, ConversionError>
pub fn i32(&self, key: &str) -> Result<Option<i32>, ConversionError>
pub fn path_i32(&self, path: &str) -> Result<Option<i32>, ConversionError>
pub fn string(&self, key: &str) -> Result<Option<String>, ConversionError>
pub fn path_string(&self, path: &str) -> Result<Option<String>, ConversionError>
pub fn dict(&self, key: &str) -> Result<Option<MemoryReference>, ConversionError>
pub fn path_dict(
&self,
path: &str
) -> Result<Option<MemoryReference>, ConversionError>
sourcepub fn dict_or_create(
&self,
key: &str
) -> Result<MemoryReference, UnexpectedTypeError>
pub fn dict_or_create(
&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>
pub fn del(&self, key: &str)
pub fn path_del(&self, path: &str)
pub fn get<T>(&self, key: &str) -> Result<T, ConversionError>where
T: TryFrom<Value, Error = ConversionError>,
pub fn get_path<T>(&self, path: &str) -> Result<T, ConversionError>where
T: TryFrom<Value, Error = ConversionError>,
pub fn set<T>(&self, key: &str, value: T)where
T: JsSerialize,
pub fn path_set<T>(&self, path: &str, value: T)where
T: JsSerialize,
pub fn arr<T>(&self, key: &str) -> Result<Option<Vec<T>>, ConversionError>where
T: TryFrom<Value, Error = ConversionError>,
pub fn path_arr<T>(&self, path: &str) -> Result<Option<Vec<T>>, ConversionError>where
T: TryFrom<Value, Error = ConversionError>,
Trait Implementations
sourceimpl AsRef<Reference> for MemoryReference
impl AsRef<Reference> for MemoryReference
sourceimpl Default for MemoryReference
impl Default for MemoryReference
Auto Trait Implementations
impl RefUnwindSafe for MemoryReference
impl Send for MemoryReference
impl Sync for MemoryReference
impl Unpin for MemoryReference
impl UnwindSafe for MemoryReference
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