use crate::{AnyOutput, ChainProcess, Grouped, ProgramCollect}; /// Represents a type that can be routed within a group. /// /// Used to indicate that a group member can be routed into another [`ChainProcess`] /// within the execution logic of a [`Chain`](https://docs.rs/mingling/latest/mingling/trait.Chain.html). /// /// # Blanket impl /// /// When a type implements [`Grouped`], it automatically gets a corresponding [`Routable`] /// implementation, meaning all types deriving [`Grouped`] can flow through the program loop. /// /// # Reference /// /// You can use the [`routeify`](https://docs.rs/mingling/latest/mingling/macros/attr.routeify.html) /// macro and the [`route!`](https://docs.rs/mingling/latest/mingling/macros/macro.route.html) macro /// to build flexible program execution logic. /// /// # Example /// /// ``` /// # use mingling_core::Routable; /// # use mingling_core::ChainProcess; /// # use mingling_core::MockProgramCollect as ThisProgram; /// # use mingling_core::Grouped; /// # unsafe impl Grouped for Foo { /// # fn member_id() -> ThisProgram { /// # ThisProgram::Foo /// # } /// # } /// struct Foo; /// /// // With `Grouped` implemented, the type automatically implements `Routable` /// // and can be converted into a `ChainProcess` via `to_chain` / `to_render`: /// fn takes_chain>(value: T) -> ChainProcess { /// value.to_chain() /// } /// /// # fn main() { /// # takes_chain(Foo); /// # } /// ``` pub trait Routable where Self: Sized + 'static, { /// Converts the current type into a [`ChainProcess`] that can be used for execution in a program chain (`Chain`). /// /// # Return value /// /// Returns a [`ChainProcess`] wrapping the current value, /// which will be scheduled for execution in the program chain. /// /// # Example /// /// ``` /// # use mingling_core::{Grouped, ChainProcess}; /// # use mingling_core::MockProgramCollect as ThisProgram; /// # unsafe impl Grouped for StateMyType { /// # fn member_id() -> ThisProgram { /// # ThisProgram::Foo /// # } /// # } /// use mingling_core::Routable; /// /// struct StateMyType; /// /// let my_type = StateMyType; /// let process: ChainProcess = my_type.to_chain(); /// ``` fn to_chain(self) -> ChainProcess; /// Converts the current type into a [`ChainProcess`] that can be used for the rendering pipeline. /// /// # Return value /// /// Returns a [`ChainProcess`] wrapping the current value, /// which will be scheduled for execution in the rendering pipeline. /// /// # Example /// /// ``` /// # use mingling_core::{Grouped, ChainProcess}; /// # use mingling_core::MockProgramCollect as ThisProgram; /// # unsafe impl Grouped for StateMyType { /// # fn member_id() -> ThisProgram { /// # ThisProgram::Foo /// # } /// # } /// use mingling_core::Routable; /// /// struct StateMyType; /// /// let my_type = StateMyType; /// let process: ChainProcess = my_type.to_render(); /// ``` fn to_render(self) -> ChainProcess; } impl Routable for T where C: ProgramCollect, T: Grouped + Send, { fn to_chain(self) -> ChainProcess { AnyOutput::new(self).route_chain() } fn to_render(self) -> ChainProcess { AnyOutput::new(self).route_renderer() } }