Skip to main content

GMRef

Struct GMRef 

Source
pub struct GMRef<T> { /* private fields */ }
Expand description

A reference to another GameMaker element.

This is typically a Reference by ID in the data file format, but is also used for texture page items (which are pointers).

GMRef has (fake) generic types to make it clearer which type it belongs to.

  • Example without: pub texture_mask: GMRef
  • Example with: pub texture_mask: GMRef<GMSprite>

It can be resolved to the data it references using the .resolve() method, which needs the vector the elements are stored in. This means that removing or inserting elements in the middle of the list will shift all their GMRefs; breaking them.

Implementations§

Source§

impl<T> GMRef<T>

Source

pub const fn new(index: u32) -> Self

Creates a new GameMaker reference with the specified index.

The fake generic type can often be omitted (if the compiler can infer it).

Source

pub fn resolve(self, elements_by_index: &[T]) -> Result<&T>

Attempts to resolve this reference to an element in the given list by its index.

Returns a reference to the element if the index is valid, or an error string if out of bounds.

§Parameters
  • elements_by_index: A vector of elements indexed by self.index.
§Errors

Returns an error if self.index is out of bounds for the provided vector.

Source

pub fn resolve_mut(self, elements_by_index: &mut [T]) -> Result<&mut T>

Attempts to resolve this reference to an element in the given list by its index.

Returns a reference to the element if the index is valid, or an error string if out of bounds.

§Parameters
  • elements_by_index: A vector of elements indexed by self.index.
§Errors

Returns an error if self.index is out of bounds for the provided vector.

Trait Implementations§

Source§

impl<T> Clone for GMRef<T>

Source§

fn clone(&self) -> Self

Returns a duplicate 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 GMRef<T>

Source§

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

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

impl From<Collision> for GMRef<GMGameObject>

Source§

fn from(collision: Collision) -> Self

Converts to this type from the input type.
Source§

impl From<GMRef<GMGameObject>> for Collision

Source§

fn from(game_object_ref: GMRef<GMGameObject>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<GMRef<T>> for u32

Source§

fn from(gm_ref: GMRef<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<GMRef<T>> for usize

Source§

fn from(gm_ref: GMRef<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<u32> for GMRef<T>

Source§

fn from(index: u32) -> Self

Converts to this type from the input type.
Source§

impl<T> From<usize> for GMRef<T>

Source§

fn from(index: usize) -> Self

Converts to this type from the input type.
Source§

impl<T> Hash for GMRef<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> PartialEq for GMRef<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Copy for GMRef<T>

Source§

impl<T> Eq for GMRef<T>

Source§

impl<T> GMElement for GMRef<T>

Auto Trait Implementations§

§

impl<T> Freeze for GMRef<T>

§

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

§

impl<T> Send for GMRef<T>
where T: Send,

§

impl<T> Sync for GMRef<T>
where T: Sync,

§

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

§

impl<T> UnsafeUnpin for GMRef<T>

§

impl<T> UnwindSafe for GMRef<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.