ReflectQueryable

Struct ReflectQueryable 

Source
pub struct ReflectQueryable(/* private fields */);
Expand description

A reflect trait extending ReflectComponent with query methods.

ReflectComponent doesn’t have methods to get

Implementations§

Source§

impl ReflectQueryable

Source

pub const fn get(&self) -> &ReflectQueryableFns

Return the function pointers implementing the ReflectQueryable methods.

Source

pub fn reflect_ref<'a>( &self, entity: EntityRef<'a>, ) -> Option<Ref<'a, dyn Reflect>>

Gets the value of this Component type from the entity as a reflected reference, with tick data in Ref.

Source§

impl ReflectQueryable

Get a single entity with the reflected queryable Component.

Source

pub fn get_single<'a>( &self, world: &'a mut World, ) -> Result<&'a dyn Reflect, QuerySingleError>

Get a single &dyn Reflect of the underyling Component from World, failing if there isn’t exactly one Entity matching this description.

Consider using ReflectQueryable::query followed by .next() if you want to get a value even if there is more than one Entity with the underlying Component.

§Errors

This will return an Err if:

  • There is no Entity with the underyling Component in world.
  • There is more than one Entity with the underyling Component in world.
Source

pub fn get_single_ref<'a>( &self, world: &'a mut World, ) -> Result<Ref<'a, dyn Reflect>, QuerySingleError>

Get a single Ref<dyn Reflect> of the underyling Component from World, failing if there isn’t exactly one Entity matching this description.

Consider using ReflectQueryable::query_ref followed by .next() if you want to get a value even if there is more than one Entity with the underlying Component.

§Errors

This will return an Err if:

  • There is no Entity with the underyling Component in world.
  • There is more than one Entity with the underyling Component in world.
Source

pub fn get_single_mut<'a>( &self, world: &'a mut World, ) -> Result<Mut<'a, dyn Reflect>, QuerySingleError>

Get a single Mut<dyn Reflect> of the underyling Component from World, failing if there isn’t exactly one Entity matching this description.

Consider using ReflectQueryable::query_mut followed by .next() if you want to get a value even if there is more than one Entity with the underlying Component.

§Errors

This will return an Err if:

  • There is no Entity with the underyling Component in world.
  • There is more than one Entity with the underyling Component in world.
Source

pub fn get_single_entity( &self, world: &mut World, ) -> Result<Entity, QuerySingleError>

Get a single Entity of the underyling Component from World, failing if there isn’t exactly one Entity matching this description.

Consider using ReflectQueryable::query_entities followed by .next() if you want to get a value even if there is more than one Entity with the underlying Component.

§Errors

This will return an Err if:

  • There is no Entity with the underyling Component in world.
  • There is more than one Entity with the underyling Component in world.
Source§

impl ReflectQueryable

Query all entities with the reflected queryable Component.

Source

pub fn query(&self, world: &mut World) -> Querydyn

Get a Querydyn to iterate over all &dyn Reflect with the underlying Component from world.

Use ReflectQueryable::get_single for a version that returns a single element directly.

§Example
use std::any::TypeId;
use bevy::prelude::{Reflect, ReflectComponent, Component, World};
use bevy::reflect::TypeRegistryInternal as TypeRegistry;
use cuicui_reflect_query::ReflectQueryable;

#[derive(Component, Reflect, Default)]
#[reflect(Component, Queryable)]
struct Zoobazee {
    bee: u32,
    baboo: String,
}
fn reflect_query(world: &mut World, registry: &TypeRegistry) {
    let type_data = registry
        .get_type_data::<ReflectQueryable>(TypeId::of::<Zoobazee>())
        .unwrap();

    let mut query = type_data.query(world);

    for element in query.iter(world) {
        println!("{element:?}");
    }
}
Source

pub fn query_entities(&self, world: &mut World) -> EntityQuerydyn

Get a EntityQuerydyn to iterate over all Entity with the underlying Component from world.

Use ReflectQueryable::get_single_entity for a version that returns a single element directly.

§Example
use std::any::TypeId;
use bevy::prelude::{Reflect, ReflectComponent, Component, World};
use bevy::reflect::TypeRegistryInternal as TypeRegistry;
use cuicui_reflect_query::ReflectQueryable;

#[derive(Component, Reflect, Default)]
#[reflect(Component, Queryable)]
struct Zoobazee {
    bee: u32,
    baboo: String,
}
fn reflect_query(world: &mut World, registry: &TypeRegistry) {
    let type_data = registry
        .get_type_data::<ReflectQueryable>(TypeId::of::<Zoobazee>())
        .unwrap();

    let mut query = type_data.query_entities(world);

    for element in query.iter(world) {
        println!("{element:?}");
    }
}
Source

pub fn query_ref(&self, world: &mut World) -> RefQuerydyn

Get a RefQuerydyn to iterate over all Ref<dyn Reflect> with the underlying Component from world.

Use ReflectQueryable::get_single_ref for a version that returns a single element directly.

§Example
use std::any::TypeId;
use bevy::prelude::{Reflect, ReflectComponent, Component, World};
use bevy::reflect::TypeRegistryInternal as TypeRegistry;
use cuicui_reflect_query::ReflectQueryable;

#[derive(Component, Reflect, Default)]
#[reflect(Component, Queryable)]
struct Zoobazee {
    bee: u32,
    baboo: String,
}
fn reflect_query(world: &mut World, registry: &TypeRegistry) {
    let type_data = registry
        .get_type_data::<ReflectQueryable>(TypeId::of::<Zoobazee>())
        .unwrap();

    let mut query = type_data.query_ref(world);

    for element in query.iter(world) {
        println!("{element:?}");
    }
}
Source

pub fn query_mut(&self, world: &mut World) -> MutQuerydyn

Get a MutQuerydyn to iterate over all Mut<dyn Reflect> with the underlying Component from world.

Use ReflectQueryable::get_single_mut for a version that returns a single element directly.

§Example
use std::any::TypeId;
use bevy::prelude::{Reflect, ReflectComponent, Component, World};
use bevy::reflect::TypeRegistryInternal as TypeRegistry;
use cuicui_reflect_query::ReflectQueryable;

#[derive(Component, Reflect, Default)]
#[reflect(Component, Queryable)]
struct Zoobazee {
    bee: u32,
    baboo: String,
}
fn reflect_query(world: &mut World, registry: &TypeRegistry) {
    let type_data = registry
        .get_type_data::<ReflectQueryable>(TypeId::of::<Zoobazee>())
        .unwrap();

    let mut query = type_data.query_mut(world);

    for element in query.iter(world) {
        println!("{element:?}");
    }
}

Trait Implementations§

Source§

impl Clone for ReflectQueryable

Source§

fn clone(&self) -> ReflectQueryable

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<C: Component + Reflect> FromType<C> for ReflectQueryable

Source§

fn from_type() -> Self

Auto Trait Implementations§

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Event for T
where T: Send + Sync + 'static,