spring_boot/plugin/
component.rs

1use std::{any::Any, sync::Arc};
2
3#[derive(Clone)]
4pub struct ComponentRef(Arc<dyn Any + Send + Sync>);
5
6impl ComponentRef {
7    pub fn new<T>(component: T) -> Self
8    where
9        T: Any + Send + Sync,
10    {
11        Self(Arc::new(component))
12    }
13
14    pub fn downcast<T>(self) -> Option<Arc<T>>
15    where
16        T: Any + Send + Sync,
17    {
18        self.0.downcast::<T>().ok()
19    }
20}