3535//!
3636//! ```rust
3737//! use std::fmt::Show;
38- //! use std::any::{ Any, AnyRefExt} ;
38+ //! use std::any::Any;
3939//!
4040//! // Logger function for any type that implements Show.
4141//! fn log<T: Any+Show>(value: &T) {
@@ -102,24 +102,11 @@ impl<T: 'static> Any for T {
102102// Implemented as three extension traits so that the methods can be generic.
103103///////////////////////////////////////////////////////////////////////////////
104104
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 {
109106 /// Returns true if the boxed type is the same as `T`
110107 #[ 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 {
121108 #[ inline]
122- fn is < T : ' static > ( self ) -> bool {
109+ pub fn is < T : ' static > ( & self ) -> bool {
123110 // Get TypeId of the type this function is instantiated with
124111 let t = TypeId :: of :: < T > ( ) ;
125112
@@ -130,8 +117,11 @@ impl<'a> AnyRefExt<'a> for &'a Any {
130117 t == boxed
131118 }
132119
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" ]
133123 #[ inline]
134- fn downcast_ref < T : ' static > ( self ) -> Option < & ' a T > {
124+ pub fn downcast_ref < ' a , T : ' static > ( & ' a self ) -> Option < & ' a T > {
135125 if self . is :: < T > ( ) {
136126 unsafe {
137127 // Get the raw representation of the trait object
@@ -144,22 +134,12 @@ impl<'a> AnyRefExt<'a> for &'a Any {
144134 None
145135 }
146136 }
147- }
148137
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 > {
153138 /// Returns some mutable reference to the boxed value if it is of type `T`, or
154139 /// `None` if it isn't.
155140 #[ 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 {
161141 #[ 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 > {
163143 if self . is :: < T > ( ) {
164144 unsafe {
165145 // Get the raw representation of the trait object
0 commit comments