fix(rustup): get rid of slice pattern, add Reflect bounds

* remove slice pattern
* add `Reflect` trait bounds where necessary
This commit is contained in:
Florian Hartwig
2015-03-29 18:01:05 +02:00
parent 8e1cd5e6e2
commit c9f2c841ff
3 changed files with 23 additions and 21 deletions

View File

@@ -7,6 +7,7 @@ use std::mem;
use std::path::Path;
use std::raw::{self, TraitObject};
use std::sync::Arc;
use std::marker::Reflect;
use openssl::ssl::{Ssl, SslStream, SslContext};
use openssl::ssl::SslVerifyMode::SslVerifyNone;
@@ -117,13 +118,13 @@ impl NetworkStream + Send {
impl NetworkStream + Send {
/// Is the underlying type in this trait object a T?
#[inline]
pub fn is<T: 'static>(&self) -> bool {
pub fn is<T: Reflect + 'static>(&self) -> bool {
self.get_type_id() == TypeId::of::<T>()
}
/// If the underlying type is T, get a reference to the contained data.
#[inline]
pub fn downcast_ref<T: 'static>(&self) -> Option<&T> {
pub fn downcast_ref<T: Reflect + 'static>(&self) -> Option<&T> {
if self.is::<T>() {
Some(unsafe { self.downcast_ref_unchecked() })
} else {
@@ -134,7 +135,7 @@ impl NetworkStream + Send {
/// If the underlying type is T, get a mutable reference to the contained
/// data.
#[inline]
pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T> {
pub fn downcast_mut<T: Reflect + 'static>(&mut self) -> Option<&mut T> {
if self.is::<T>() {
Some(unsafe { self.downcast_mut_unchecked() })
} else {
@@ -143,7 +144,7 @@ impl NetworkStream + Send {
}
/// If the underlying type is T, extract it.
pub fn downcast<T: 'static>(self: Box<NetworkStream + Send>)
pub fn downcast<T: Reflect + 'static>(self: Box<NetworkStream + Send>)
-> Result<Box<T>, Box<NetworkStream + Send>> {
if self.is::<T>() {
Ok(unsafe { self.downcast_unchecked() })