diff options
Diffstat (limited to 'components/devtools/actor.rs')
-rw-r--r-- | components/devtools/actor.rs | 60 |
1 files changed, 6 insertions, 54 deletions
diff --git a/components/devtools/actor.rs b/components/devtools/actor.rs index 87c3d45f139..2b4f408cd45 100644 --- a/components/devtools/actor.rs +++ b/components/devtools/actor.rs @@ -4,13 +4,11 @@ /// General actor system infrastructure. -use std::any::{Any, AnyRefExt, AnyMutRefExt}; +use std::any::Any; use std::collections::HashMap; use std::cell::{Cell, RefCell}; -use std::intrinsics::TypeId; use std::io::TcpStream; -use std::mem::{transmute, transmute_copy, replace}; -use std::raw::TraitObject; +use std::mem::replace; use serialize::json; /// A common trait for all devtools actors that encompasses an immutable name @@ -25,46 +23,6 @@ pub trait Actor : Any { fn name(&self) -> String; } -impl<'a> AnyMutRefExt<'a> for &'a mut (Actor + 'a) { - fn downcast_mut<T: 'static>(self) -> Option<&'a mut T> { - if self.is::<T>() { - unsafe { - // Get the raw representation of the trait object - let to: TraitObject = transmute_copy(&self); - - // Extract the data pointer - Some(transmute(to.data)) - } - } else { - None - } - } -} - -impl<'a> AnyRefExt<'a> for &'a (Actor + 'a) { - fn is<T: 'static>(self) -> bool { - // This implementation is only needed so long as there's a Rust bug that - // prevents downcast_ref from giving realistic return values. - let t = TypeId::of::<T>(); - let boxed: TypeId = (*self).get_type_id(); - t == boxed - } - - fn downcast_ref<T: 'static>(self) -> Option<&'a T> { - if self.is::<T>() { - unsafe { - // Get the raw representation of the trait object - let to: TraitObject = transmute_copy(&self); - - // Extract the data pointer - Some(transmute(to.data)) - } - } else { - None - } - } -} - /// A list of known, owned actors. pub struct ActorRegistry { actors: HashMap<String, Box<Actor+Send+Sized>>, @@ -130,20 +88,14 @@ impl ActorRegistry { /// Find an actor by registered name pub fn find<'a, T: 'static>(&'a self, name: &str) -> &'a T { - //FIXME: Rust bug forces us to implement bogus Any for Actor since downcast_ref currently - // fails for unknown reasons. - /*let actor: &Actor+Send+Sized = *self.actors.find(&name.to_string()).unwrap(); - (actor as &Any).downcast_ref::<T>().unwrap()*/ - self.actors.get(&name.to_string()).unwrap().downcast_ref::<T>().unwrap() + let actor: &Any = self.actors.get(&name.to_string()).unwrap(); + actor.downcast_ref::<T>().unwrap() } /// Find an actor by registered name pub fn find_mut<'a, T: 'static>(&'a mut self, name: &str) -> &'a mut T { - //FIXME: Rust bug forces us to implement bogus Any for Actor since downcast_ref currently - // fails for unknown reasons. - /*let actor: &mut Actor+Send+Sized = *self.actors.find_mut(&name.to_string()).unwrap(); - (actor as &mut Any).downcast_mut::<T>().unwrap()*/ - self.actors.get_mut(&name.to_string()).unwrap().downcast_mut::<T>().unwrap() + let actor: &mut Any = self.actors.get_mut(&name.to_string()).unwrap(); + actor.downcast_mut::<T>().unwrap() } /// Attempt to process a message as directed by its `to` property. If the actor is not |