diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-20 01:11:25 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-20 01:11:25 +0800 |
| commit | 9d491352d161ee629cc47459537344ba0ea4bb35 (patch) | |
| tree | 40d847da5cfafce48c3ca99c78bcc077da4c4fb2 /mingling_core/src/any/group.rs | |
| parent | 8749087c5035fbe4c0dce0893a39e0e2265fa130 (diff) | |
Add shared `MockProgramCollect` and conditional `Groupped` bounds
Extract duplicate `MockCollect` implementations into a reusable
`MockProgramCollect` type. Conditionally require `Serialize` on the
`Groupped` trait when the `general_renderer` feature is enabled.
Diffstat (limited to 'mingling_core/src/any/group.rs')
| -rw-r--r-- | mingling_core/src/any/group.rs | 87 |
1 files changed, 70 insertions, 17 deletions
diff --git a/mingling_core/src/any/group.rs b/mingling_core/src/any/group.rs index c251286..e9fce5e 100644 --- a/mingling_core/src/any/group.rs +++ b/mingling_core/src/any/group.rs @@ -1,21 +1,74 @@ -use crate::{AnyOutput, ChainProcess}; - -/// Used to mark a type with a unique enum ID, assisting dynamic dispatch -pub trait Groupped<Group> { - /// Returns the specific enum value representing its ID within that enum - fn member_id() -> Group; - - /// Converts the grouped item into a `ChainProcess` directed to the chain route. - /// - /// This wraps the item into an `AnyOutput` and routes it to the chain processing pipeline. - fn to_chain(self) -> ChainProcess<Group> { - AnyOutput::new(self).route_chain() +#[cfg(feature = "general_renderer")] +pub use general_renderer_groupped::*; + +#[cfg(not(feature = "general_renderer"))] +pub use groupped::*; + +#[cfg(feature = "general_renderer")] +mod general_renderer_groupped { + use serde::Serialize; + + use crate::{AnyOutput, ChainProcess}; + /// Used to mark a type with a unique enum ID, assisting dynamic dispatch + pub trait Groupped<Group> + where + Self: Sized + Serialize + 'static, + { + /// Returns the specific enum value representing its ID within that enum + fn member_id() -> Group; + + /// Converts the grouped item into a `ChainProcess` directed to the chain route. + /// + /// This wraps the item into an `AnyOutput` and routes it to the chain processing pipeline. + fn to_chain(self) -> ChainProcess<Group> + where + Self: Send + Serialize, + { + AnyOutput::new(self).route_chain() + } + + /// Converts the grouped item into a `ChainProcess` directed to the render route. + /// + /// This wraps the item into an `AnyOutput` and routes it to the render processing pipeline. + fn to_render(self) -> ChainProcess<Group> + where + Self: Send + Serialize, + { + AnyOutput::new(self).route_renderer() + } } +} + +#[cfg(not(feature = "general_renderer"))] +mod groupped { + use crate::{AnyOutput, ChainProcess}; + + /// Used to mark a type with a unique enum ID, assisting dynamic dispatch + pub trait Groupped<Group> + where + Self: Sized + 'static, + { + /// Returns the specific enum value representing its ID within that enum + fn member_id() -> Group; + + /// Converts the grouped item into a `ChainProcess` directed to the chain route. + /// + /// This wraps the item into an `AnyOutput` and routes it to the chain processing pipeline. + fn to_chain(self) -> ChainProcess<Group> + where + Self: Send, + { + AnyOutput::new(self).route_chain() + } - /// Converts the grouped item into a `ChainProcess` directed to the render route. - /// - /// This wraps the item into an `AnyOutput` and routes it to the render processing pipeline. - fn to_render(self) -> ChainProcess<Group> { - AnyOutput::new(self).route_renderer() + /// Converts the grouped item into a `ChainProcess` directed to the render route. + /// + /// This wraps the item into an `AnyOutput` and routes it to the render processing pipeline. + fn to_render(self) -> ChainProcess<Group> + where + Self: Send, + { + AnyOutput::new(self).route_renderer() + } } } |
