aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/any/group.rs
blob: 2813ad54677c80e13c20ac98429157f17d2ab1af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::{AnyOutput, ChainProcess, ProgramCollect, Routable};

/// Used to mark a type with a unique enum ID, assisting dynamic dispatch
///
/// **Note:** Unlike earlier versions, `Grouped` no longer requires `Serialize`
/// even when the `structural_renderer` feature is enabled. Structured output is
/// controlled separately via the \[`StructuralData`\] trait.
pub trait Grouped<Group>
where
    Self: Sized + 'static,
{
    /// Returns the specific enum value representing its ID within that enum
    fn member_id() -> Group;
}

impl<T, C> Routable<C> for T
where
    C: ProgramCollect<Enum = C>,
    T: Grouped<C> + Send,
{
    fn to_chain(self) -> ChainProcess<C> {
        AnyOutput::new(self).route_chain()
    }

    fn to_render(self) -> ChainProcess<C> {
        AnyOutput::new(self).route_renderer()
    }
}