/// Creates an entity struct for a given handle.
///
/// Creates the appropriate entity struct for the handle and returns an error if the handle is invalid.
Creates an entity struct for a given handle.
Creates the appropriate entity struct for the handle and returns an error if the handle is invalid.
Creates an entity struct for a given handle . Creates the appropriate entity struct for the handle and returns an error if the handle is invalid .
pub fn entity_from_handle(handle: NativeEntity) -> Result<Box<dyn Entity>, EntityFromHandleError> {
  unsafe {
    if natives::entity::does_entity_exist(handle) {
      let entity_type = natives::entity::get_entity_type(handle);
      match entity_type {
        1 => {
          Ok(Box::new(
            Ped::try_from(handle).expect("Ped::try_from failed")
          ))
        } // Ped
        2 => {
          Ok(Box::new(
            Vehicle::try_from(handle).expect("Vehicle::try_from failed")
          ))
        } // Vehicle
        3 => {
          Ok(Box::new(
            Object::try_from(handle).expect("Object::try_from failed")
          ))
        } // Object
        _ => {
          Err(EntityFromHandleError::UnrecognizedEntity(
            UnrecognizedEntityTypeError {
              handle,
              entity_type
            }
          ))
        }
      }
    } else {
      Err(EntityFromHandleError::NotAnEntityHandle(
        NotAnEntityHandleError { handle }
      ))
    }
  }
}
pub fn entity_from_handle ( handle : NativeEntity ) -> Result < Box < dyn Entity > , EntityFromHandleError > { unsafe { if natives :: entity :: does_entity_exist ( handle ) { let entity_type = natives :: entity :: get_entity_type ( handle ) ; match entity_type { 1 => { Ok ( Box :: new ( Ped :: try_from ( handle ) . expect ( " " ) ) ) } // Ped 2 => { Ok ( Box :: new ( Vehicle :: try_from ( handle ) . expect ( " " ) ) ) } // Vehicle 3 => { Ok ( Box :: new ( Object :: try_from ( handle ) . expect ( " " ) ) ) } // Object _ => { Err ( EntityFromHandleError :: UnrecognizedEntity ( UnrecognizedEntityTypeError { handle , entity_type } ) ) } } } else { Err ( EntityFromHandleError :: NotAnEntityHandle ( NotAnEntityHandleError { handle } ) ) } } }
Creates an entity struct for a given handle.
Creates an entity struct for a given handle .
handle
NativeEntity