summaryrefslogtreecommitdiff
path: root/mingling_core/src/any.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-04-05 20:33:57 +0800
committer魏曹先生 <1992414357@qq.com>2026-04-05 20:33:57 +0800
commitb6876f9df6e3119331fac01c0bc954ca9f3c798b (patch)
tree030301c8d434d51fa386e9a5fff77bce5899733b /mingling_core/src/any.rs
parentb41e201e554c4ba5ad6f1e09ce58dd3d10b6a635 (diff)
Add general renderer support with serialization formats
Diffstat (limited to 'mingling_core/src/any.rs')
-rw-r--r--mingling_core/src/any.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/mingling_core/src/any.rs b/mingling_core/src/any.rs
index d550ec7..57eddfb 100644
--- a/mingling_core/src/any.rs
+++ b/mingling_core/src/any.rs
@@ -23,7 +23,7 @@ pub struct AnyOutput<G>
where
G: Display,
{
- inner: Box<dyn std::any::Any + Send + 'static>,
+ pub(crate) inner: Box<dyn std::any::Any + Send + 'static>,
pub type_id: std::any::TypeId,
pub member_id: G,
}
@@ -81,6 +81,19 @@ where
pub fn route_renderer(self) -> ChainProcess<G> {
ChainProcess::Ok((self, Next::Renderer))
}
+
+ #[cfg(feature = "general_renderer")]
+ /// Restore AnyOutput back to the original Serialize type
+ pub fn restore<T: Serialize + 'static>(self) -> Option<T> {
+ if self.type_id == std::any::TypeId::of::<T>() {
+ match self.inner.downcast::<T>() {
+ Ok(boxed) => Some(*boxed),
+ Err(_) => None,
+ }
+ } else {
+ None
+ }
+ }
}
impl<G> std::ops::Deref for AnyOutput<G>