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>

source

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.

source

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>

source§

fn clone(&self) -> JsObjectId<T>

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<T> Debug for JsObjectId<T>

source§

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

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

impl<T> Display for JsObjectId<T>

source§

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

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

impl<T> From<JsObjectId<T>> for JsString

source§

fn from(id: JsObjectId<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<JsObjectId<T>> for String

source§

fn from(id: JsObjectId<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<JsString> for JsObjectId<T>

source§

fn from(raw: JsString) -> Self

Converts to this type from the input type.
source§

impl<T> FromStr for JsObjectId<T>

§

type Err = RawObjectIdParseError

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<T> PartialEq for JsObjectId<T>

source§

fn eq(&self, o: &JsObjectId<T>) -> 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<T> Eq for JsObjectId<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for JsObjectId<T>
where T: RefUnwindSafe,

§

impl<T> !Send for JsObjectId<T>

§

impl<T> !Sync for JsObjectId<T>

§

impl<T> Unpin for JsObjectId<T>
where T: Unpin,

§

impl<T> UnwindSafe for JsObjectId<T>
where T: UnwindSafe,

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.