pub struct InstanceRef<'a> {
pub entity: &'a EntityInstance,
}
Fields§
§entity: &'a EntityInstance
Implementations§
Source§impl<'a> InstanceRef<'a>
impl<'a> InstanceRef<'a>
Sourcepub fn get_type(&self) -> &'a String
pub fn get_type(&self) -> &'a String
Get the category that this instance belongs to. Exactly matches the string name found in the LDTK entities list
Sourcepub fn try_get_typed_id<T: FromStr>(&self) -> Result<T, T::Err>
pub fn try_get_typed_id<T: FromStr>(&self) -> Result<T, T::Err>
Try to get a type safe representation of this entity’s type, as long as the target type can be produced from a str representation
§Example
#[derive(PartialEq, Debug)]
enum MyEntityType {
Player,
Monster,
}
impl FromStr for MyEntityType {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"player" => Ok(Self::Player),
"monster" => Ok(Self::Monster),
}
}
}
let data_from_ldtk: EntityInstance = EntityInstance {
identifier: "player".to_string(),
// ...other properties
};
let my_entity_type: InstanceRef<'_> = process_ldtk_data();
assert_eq!(my_entity_type.try_get_typed_id(), Ok(MyEntityType::Player));
Sourcepub fn property(&self, name: impl ToString) -> Value
pub fn property(&self, name: impl ToString) -> Value
Retrieve an associated property from this instance. Will return serde_json::Value::Null if there is no property with the given name
Sourcepub fn instance_ref(&self) -> &EntityInstance
pub fn instance_ref(&self) -> &EntityInstance
Get a reference to the inner instance of this instance ref
Trait Implementations§
Source§impl<'a> Clone for InstanceRef<'a>
impl<'a> Clone for InstanceRef<'a>
Source§fn clone(&self) -> InstanceRef<'a>
fn clone(&self) -> InstanceRef<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<'a> Freeze for InstanceRef<'a>
impl<'a> RefUnwindSafe for InstanceRef<'a>
impl<'a> Send for InstanceRef<'a>
impl<'a> Sync for InstanceRef<'a>
impl<'a> Unpin for InstanceRef<'a>
impl<'a> UnwindSafe for InstanceRef<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more