tramli/clone_any.rs
1use std::any::Any;
2
3/// Trait combining Any + Clone + Send for type-erased cloneable storage.
4///
5/// All types stored in FlowContext must implement this trait.
6/// Use `#[derive(Clone)]` on your types — the blanket impl covers the rest.
7pub trait CloneAny: Any + Send {
8 fn clone_box(&self) -> Box<dyn CloneAny>;
9 fn as_any(&self) -> &dyn Any;
10}
11
12impl<T: Any + Clone + Send + 'static> CloneAny for T {
13 fn clone_box(&self) -> Box<dyn CloneAny> {
14 Box::new(self.clone())
15 }
16 fn as_any(&self) -> &dyn Any {
17 self
18 }
19}
20
21impl Clone for Box<dyn CloneAny> {
22 fn clone(&self) -> Self {
23 self.clone_box()
24 }
25}