diff options
Diffstat (limited to 'mingling_core/src/any.rs')
| -rw-r--r-- | mingling_core/src/any.rs | 15 |
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> |
