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
54
55
56
57
58
59
60
61
62
63
64
//! Provides [`MultiAny`], a trait for dynamic typing that allows downcasting to
//! concrete types and trait objects.
//!
//! [Cargo features](`features`).
pub use *;
pub use *;
pub use multi_any;
pub use *;
/// Derive macro for `MultiAny`.
///
/// See [`MultiAny`] for usage and examples.
pub use MultiAny;
/// # Cargo features
///
/// - `stable` (default): Uses the `ptr_meta` crate for pointer metadata operations.
/// - `nightly`: Uses nightly Rust's built-in `ptr_metadata` feature.
///
/// ## Usage
///
/// On stable Rust (default), annotate traits with `#[multi_any]`:
/// ```
/// use multi_any::*;
///
/// #[multi_any]
/// trait SomeTrait {}
///
/// #[derive(MultiAny)]
/// #[multi_any(SomeTrait)]
/// struct Foo;
/// impl SomeTrait for Foo {}
///
/// let foo: Box<dyn MultiAny> = Box::new(Foo);
/// assert!(foo.downcast_ref::<dyn SomeTrait>().is_some())
/// ```
///
/// On nightly Rust with the "nightly" feature enabled, it is possible to omit `#[multi_any]`
/// ```
/// #[cfg(feature="nightly")]
/// {
/// use multi_any::*;
///
/// // no annotation here
/// trait SomeTrait {}
///
/// #[derive(MultiAny)]
/// #[multi_any(SomeTrait)]
/// struct Foo;
/// impl SomeTrait for Foo {}
///
/// let foo: Box<dyn MultiAny> = Box::new(Foo);
/// assert!(foo.downcast_ref::<dyn SomeTrait>().is_some())
/// }
/// ```