Struct screeps::js_collections::JsObjectId
source · pub struct JsObjectId<T> {
pub raw: JsString,
/* private fields */
}
Expand description
Represents a reference to an Object ID string in JavaScript memory, typed according to the object type Rust expects for the object after resolving.
Use ObjectId
if a value stored in Rust memory is preferred; the
JavaScript representation can be harder to work with in Rust code due to
lack of visibility on the underlying string and lack of most trait
implementations, and consumes more memory, but is faster to resolve and may
be useful with objects you plan to resolve frequently.
This object ID is typed, but not strictly, and can be converted into
referring into another type of object with JsObjectId::into_type
.
Fields§
§raw: JsString
Implementations§
source§impl<T> JsObjectId<T>
impl<T> JsObjectId<T>
sourcepub fn into_type<U>(self) -> JsObjectId<U>
pub fn into_type<U>(self) -> JsObjectId<U>
Changes the type this JsObjectId
points to, unchecked.
This will allow changing to any type - JsObjectId
makes no guarantees
about its ID matching the type of any object in the game that it
actually points to.
sourcepub fn resolve(&self) -> Option<T>where
T: MaybeHasId + JsCast,
pub fn resolve(&self) -> Option<T>where
T: MaybeHasId + JsCast,
Resolves this ID into an object, assuming the type T
is the correct
type of object that this ID refers to. If the ID has been converted to
an invalid type, using the returned object in a way not valid for its
type will cause a panic.
Will return None
if this object no longer exists, or is in a room we
don’t have vision for.
Trait Implementations§
source§impl<T> Clone for JsObjectId<T>
impl<T> Clone for JsObjectId<T>
source§fn clone(&self) -> JsObjectId<T>
fn clone(&self) -> JsObjectId<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T> Debug for JsObjectId<T>
impl<T> Debug for JsObjectId<T>
source§impl<T> Display for JsObjectId<T>
impl<T> Display for JsObjectId<T>
source§impl<T> From<JsObjectId<T>> for JsString
impl<T> From<JsObjectId<T>> for JsString
source§fn from(id: JsObjectId<T>) -> Self
fn from(id: JsObjectId<T>) -> Self
source§impl<T> From<JsObjectId<T>> for String
impl<T> From<JsObjectId<T>> for String
source§fn from(id: JsObjectId<T>) -> Self
fn from(id: JsObjectId<T>) -> Self
source§impl<T> From<JsString> for JsObjectId<T>
impl<T> From<JsString> for JsObjectId<T>
source§impl<T> FromStr for JsObjectId<T>
impl<T> FromStr for JsObjectId<T>
source§impl<T> PartialEq for JsObjectId<T>
impl<T> PartialEq for JsObjectId<T>
source§fn eq(&self, o: &JsObjectId<T>) -> bool
fn eq(&self, o: &JsObjectId<T>) -> bool
self
and other
values to be equal, and is used
by ==
.