Kind

Trait Kind 

Source
pub trait Kind:
    Sized
    + 'static
    + Send
    + Sync {
    type Filter: QueryFilter;

    // Provided method
    fn debug_name() -> String { ... }
}
Expand description

A type which represents the kind of an Entity.

An entity is of kind T if it matches Query<Entity, <T as Kind>::Filter>.

By default, an entity with a Component of type T is also of kind T.

§Examples


#[derive(Component)]
struct Apple;

#[derive(Component)]
struct Orange;

struct Fruit;

impl Kind for Fruit {
    type Filter = Or<(With<Apple>, With<Orange>)>;
}

fn fruits(query: Query<Instance<Fruit>>) {
    for fruit in query.iter() {
        println!("{fruit:?} is a fruit!");
    }
}

Required Associated Types§

Source

type Filter: QueryFilter

The QueryFilter which defines this kind.

Provided Methods§

Source

fn debug_name() -> String

Returns the debug name of this kind.

By default, this is the short type name (without path) of this kind. This is mainly used for Debug and Display implementations.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Kind for Any

Source§

impl<T> Kind for T
where T: Component,