From 9d491352d161ee629cc47459537344ba0ea4bb35 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 20 Jun 2026 01:11:25 +0800 Subject: 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. --- mingling_core/src/any/group.rs | 87 +++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 17 deletions(-) (limited to 'mingling_core/src/any/group.rs') 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 { - /// 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 { - 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 + 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 + 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 + 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 + 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 + 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 { - 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 + where + Self: Send, + { + AnyOutput::new(self).route_renderer() + } } } -- cgit