35
35
//!
36
36
//! ```rust
37
37
//! use std::fmt::Show;
38
- //! use std::any::{ Any, AnyRefExt} ;
38
+ //! use std::any::Any;
39
39
//!
40
40
//! // Logger function for any type that implements Show.
41
41
//! fn log<T: Any+Show>(value: &T) {
@@ -102,24 +102,11 @@ impl<T: 'static> Any for T {
102
102
// Implemented as three extension traits so that the methods can be generic.
103
103
///////////////////////////////////////////////////////////////////////////////
104
104
105
- /// Extension methods for a referenced `Any` trait object
106
- #[ unstable = "this trait will not be necessary once DST lands, it will be a \
107
- part of `impl Any`"]
108
- pub trait AnyRefExt < ' a > {
105
+ impl Any {
109
106
/// Returns true if the boxed type is the same as `T`
110
107
#[ stable]
111
- fn is < T : ' static > ( self ) -> bool ;
112
-
113
- /// Returns some reference to the boxed value if it is of type `T`, or
114
- /// `None` if it isn't.
115
- #[ unstable = "naming conventions around acquiring references may change" ]
116
- fn downcast_ref < T : ' static > ( self ) -> Option < & ' a T > ;
117
- }
118
-
119
- #[ stable]
120
- impl < ' a > AnyRefExt < ' a > for & ' a Any {
121
108
#[ inline]
122
- fn is < T : ' static > ( self ) -> bool {
109
+ pub fn is < T : ' static > ( & self ) -> bool {
123
110
// Get TypeId of the type this function is instantiated with
124
111
let t = TypeId :: of :: < T > ( ) ;
125
112
@@ -130,8 +117,11 @@ impl<'a> AnyRefExt<'a> for &'a Any {
130
117
t == boxed
131
118
}
132
119
120
+ /// Returns some reference to the boxed value if it is of type `T`, or
121
+ /// `None` if it isn't.
122
+ #[ unstable = "naming conventions around acquiring references may change" ]
133
123
#[ inline]
134
- fn downcast_ref < T : ' static > ( self ) -> Option < & ' a T > {
124
+ pub fn downcast_ref < ' a , T : ' static > ( & ' a self ) -> Option < & ' a T > {
135
125
if self . is :: < T > ( ) {
136
126
unsafe {
137
127
// Get the raw representation of the trait object
@@ -144,22 +134,12 @@ impl<'a> AnyRefExt<'a> for &'a Any {
144
134
None
145
135
}
146
136
}
147
- }
148
137
149
- /// Extension methods for a mutable referenced `Any` trait object
150
- #[ unstable = "this trait will not be necessary once DST lands, it will be a \
151
- part of `impl Any`"]
152
- pub trait AnyMutRefExt < ' a > {
153
138
/// Returns some mutable reference to the boxed value if it is of type `T`, or
154
139
/// `None` if it isn't.
155
140
#[ unstable = "naming conventions around acquiring references may change" ]
156
- fn downcast_mut < T : ' static > ( self ) -> Option < & ' a mut T > ;
157
- }
158
-
159
- #[ stable]
160
- impl < ' a > AnyMutRefExt < ' a > for & ' a mut Any {
161
141
#[ inline]
162
- fn downcast_mut < T : ' static > ( self ) -> Option < & ' a mut T > {
142
+ pub fn downcast_mut < ' a , T : ' static > ( & ' a mut self ) -> Option < & ' a mut T > {
163
143
if self . is :: < T > ( ) {
164
144
unsafe {
165
145
// Get the raw representation of the trait object
0 commit comments