7bdb5b0a047592cc95157512f311a08098c47f28
[anymap] / src / with_clone.rs
1 use std::fmt;
2
3 #[doc(hidden)]
4 pub trait CloneToAny {
5 /// Clone `self` into a new `Box<Any>` object.
6 fn clone_to_any(&self) -> Box<Any>;
7 }
8
9 impl<T: Any + Clone> CloneToAny for T {
10 fn clone_to_any(&self) -> Box<Any> {
11 Box::new(self.clone())
12 }
13 }
14
15 #[doc(hidden)]
16 /// Pretty much just `std::any::Any + Clone`.
17 pub trait Any: ::std::any::Any + CloneToAny { }
18
19 impl<T: ::std::any::Any + Clone> Any for T { }
20
21 impl Clone for Box<Any> {
22 fn clone(&self) -> Box<Any> {
23 (**self).clone_to_any()
24 }
25 }
26
27 impl<'a> fmt::Debug for &'a Any {
28 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29 f.pad("&Any")
30 }
31 }
32
33 impl<'a> fmt::Debug for Box<Any> {
34 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
35 f.pad("Box<Any>")
36 }
37 }