Implement Reflect trait with a variant on the standard OIBIT
semantics that tests the *interface* of trait objects, rather than what they close over.
This commit is contained in:
@@ -244,13 +244,13 @@ pub trait BoxAny {
|
||||
/// Returns the boxed value if it is of type `T`, or
|
||||
/// `Err(Self)` if it isn't.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>>;
|
||||
fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>>;
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl BoxAny for Box<Any> {
|
||||
#[inline]
|
||||
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
|
||||
fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
|
||||
if self.is::<T>() {
|
||||
unsafe {
|
||||
// Get the raw representation of the trait object
|
||||
@@ -270,7 +270,7 @@ impl BoxAny for Box<Any> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl BoxAny for Box<Any+Send> {
|
||||
#[inline]
|
||||
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
|
||||
fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
|
||||
<Box<Any>>::downcast(self)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user