flecs_ecs 0.2.0

Rust API for the C/CPP flecs ECS library <https://github.com/SanderMertens/flecs>
use super::*;
use crate::prelude::*;
use crate::sys;

impl World {
    /// Constructs a `Alert` from an existing entity.
    ///
    /// This function upcasts the given `entity` to a `Alert`, assuming the entity represents a alert.
    /// The purpose is to facilitate the interaction with entities that are specifically alerts within the ECS.
    ///
    /// # Arguments
    /// * `entity` - An `EntityView` that represents a alert within the world.
    pub fn alert_from<'a>(&'a self, entity: EntityView<'a>) -> Alert<'a> {
        Alert::new_from_existing(entity)
    }

    /// Creates a new `AlertBuilder` instance for constructing alerts.
    ///
    /// This function initializes a `AlertBuilder` which is used to create alerts that match specific components.
    /// It is a generic method that works with any component types that implement the `QueryTuple` trait.
    ///
    /// # Type Parameters
    /// - `Components`: The components to match on. Must implement the `QueryTuple` trait.
    ///
    /// # See also
    ///
    /// * [`World::alert_named()`]
    pub fn alert<Components>(&self) -> AlertBuilder<'_, Components>
    where
        Components: QueryTuple,
    {
        AlertBuilder::<Components>::new(self)
    }

    /// Creates a new named `AlertBuilder` instance.
    ///
    /// Similar to `alert_builder`, but allows naming the alert for easier identification and debugging.
    /// The name does not affect the alert's behavior.
    ///
    /// # Arguments
    /// * `name` - A string slice representing the name of the alert.
    ///
    /// # Type Parameters
    /// - `Components`: The components to match on. Must implement the `QueryTuple` trait.
    ///
    /// # See also
    ///
    /// * [`World::alert()`]
    pub fn alert_named<'a, Components>(&'a self, name: &str) -> AlertBuilder<'a, Components>
    where
        Components: QueryTuple,
    {
        AlertBuilder::<Components>::new_named(self, name)
    }

    /// Creates a `AlertBuilder` from a alert description.
    ///
    /// This function allows creating a alert based on a predefined alert description,
    /// facilitating more dynamic or configuration-driven alert creation.
    ///
    /// # Arguments
    /// * `desc` - A alert description that outlines the parameters for the alert builder.
    ///
    /// # Type Parameters
    /// - `Components`: The components to match on. Must implement the `QueryTuple` trait.
    pub fn alert_builder_from_desc<Components>(
        &self,
        desc: sys::ecs_alert_desc_t,
    ) -> AlertBuilder<'_, Components>
    where
        Components: QueryTuple,
    {
        AlertBuilder::<Components>::new_from_desc(self, desc)
    }
}