1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use Any;
/// This trait allows downcasting `dyn Trait` to `dyn Any`,
/// which is neccesary when using the `downcast` functions of Any with another trait
///
/// # Examples
///
/// ```rust
/// use std::any::Any;
/// use dabus::extras::AsAny;
///
/// // you have this struct
/// struct Foo;
///
/// // and want to use it as `dyn Bar`
/// trait Bar: AsAny {
/// fn do_something(&self);
/// }
///
/// impl Bar for Foo {
/// fn do_something(&self) {
/// // some work is done here probably
/// }
/// }
/// # fn main() {
/// // but how do you do that?
/// let dyn_bar: Box<dyn Bar> = Box::new(Foo);
///
/// // use it as that trait
/// dyn_bar.do_something();
///
/// // using AsAny, you can cast dyn Bar to dyn Any, and then call .downcast() on it
/// let foo_again: Foo = *dyn_bar.to_any().downcast().unwrap();
/// // tada
/// # }
/// ```