distant_net/common/
any.rs

1use std::any::Any;
2
3/// Trait used for casting support into the [`Any`] trait object
4pub trait AsAny: Any {
5    /// Converts reference to [`Any`]
6    fn as_any(&self) -> &dyn Any;
7
8    /// Converts mutable reference to [`Any`]
9    fn as_mut_any(&mut self) -> &mut dyn Any;
10
11    /// Consumes and produces `Box<dyn Any>`
12    fn into_any(self: Box<Self>) -> Box<dyn Any>;
13}
14
15/// Blanket implementation that enables any `'static` reference to convert
16/// to the [`Any`] type
17impl<T: 'static> AsAny for T {
18    fn as_any(&self) -> &dyn Any {
19        self
20    }
21
22    fn as_mut_any(&mut self) -> &mut dyn Any {
23        self
24    }
25
26    fn into_any(self: Box<Self>) -> Box<dyn Any> {
27        self
28    }
29}