#![stable(feature = "rust1", since = "1.0.0")]
use fmt;
-use marker::Send;
-use mem::transmute;
-use option::Option::{self, Some, None};
-use raw::TraitObject;
use intrinsics;
-use marker::{Reflect, Sized};
///////////////////////////////////////////////////////////////////////////////
// Any trait
///
/// [mod]: index.html
#[stable(feature = "rust1", since = "1.0.0")]
-pub trait Any: Reflect + 'static {
+pub trait Any: 'static {
/// Gets the `TypeId` of `self`.
///
/// # Examples
}
#[stable(feature = "rust1", since = "1.0.0")]
-impl<T: Reflect + 'static + ?Sized > Any for T {
+impl<T: 'static + ?Sized > Any for T {
fn get_type_id(&self) -> TypeId { TypeId::of::<T>() }
}
pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
if self.is::<T>() {
unsafe {
- // Get the raw representation of the trait object
- let to: TraitObject = transmute(self);
-
- // Extract the data pointer
- Some(&*(to.data as *const T))
+ Some(&*(self as *const Any as *const T))
}
} else {
None
pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
if self.is::<T>() {
unsafe {
- // Get the raw representation of the trait object
- let to: TraitObject = transmute(self);
-
- // Extract the data pointer
- Some(&mut *(to.data as *const T as *mut T))
+ Some(&mut *(self as *mut Any as *mut T))
}
} else {
None
/// # Examples
///
/// ```
- /// #![feature(get_type_id)]
- ///
/// use std::any::{Any, TypeId};
///
- /// fn is_string(s: &Any) -> bool {
- /// TypeId::of::<String>() == s.get_type_id()
+ /// fn is_string<T: ?Sized + Any>(_s: &T) -> bool {
+ /// TypeId::of::<String>() == TypeId::of::<T>()
/// }
///
/// fn main() {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
- pub fn of<T: ?Sized + Reflect + 'static>() -> TypeId {
+ pub fn of<T: ?Sized + 'static>() -> TypeId {
TypeId {
t: unsafe { intrinsics::type_id::<T>() },
}