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>
impl<T> GMRef<T>
Sourcepub const fn new(index: u32) -> Self
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).
Sourcepub fn resolve(self, elements_by_index: &[T]) -> Result<&T>
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 byself.index.
§Errors
Returns an error if self.index is out of bounds for the provided
vector.
Sourcepub fn resolve_mut(self, elements_by_index: &mut [T]) -> Result<&mut T>
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 byself.index.
§Errors
Returns an error if self.index is out of bounds for the provided
vector.