@@ -5,7 +5,6 @@ use std::io::{self, Read, Write};
5
5
use std:: net:: { SocketAddr , ToSocketAddrs , TcpStream , TcpListener } ;
6
6
use std:: mem;
7
7
use std:: path:: Path ;
8
- use std:: raw:: { self , TraitObject } ;
9
8
use std:: sync:: Arc ;
10
9
use std:: marker:: Reflect ;
11
10
@@ -15,6 +14,9 @@ use openssl::ssl::SslMethod::Sslv23;
15
14
use openssl:: ssl:: error:: { SslError , StreamError , OpenSslErrors , SslSessionClosed } ;
16
15
use openssl:: x509:: X509FileType ;
17
16
17
+ use typeable:: Typeable ;
18
+ use { traitobject} ;
19
+
18
20
macro_rules! try_some {
19
21
( $expr: expr) => ( match $expr {
20
22
Some ( val) => { return Err ( val) ; } ,
@@ -62,7 +64,7 @@ impl<'a, N: NetworkListener + 'a> Iterator for NetworkConnections<'a, N> {
62
64
63
65
64
66
/// An abstraction over streams that a Server can utilize.
65
- pub trait NetworkStream : Read + Write + Any + StreamClone + Send {
67
+ pub trait NetworkStream : Read + Write + Any + StreamClone + Send + Typeable {
66
68
/// Get the remote address of the underlying connection.
67
69
fn peer_addr ( & mut self ) -> io:: Result < SocketAddr > ;
68
70
}
@@ -100,31 +102,29 @@ impl Clone for Box<NetworkStream + Send> {
100
102
101
103
impl NetworkStream + Send {
102
104
unsafe fn downcast_ref_unchecked < T : ' static > ( & self ) -> & T {
103
- mem:: transmute ( mem:: transmute :: < & NetworkStream ,
104
- raw:: TraitObject > ( self ) . data )
105
+ mem:: transmute ( traitobject:: data ( self ) )
105
106
}
106
107
107
108
unsafe fn downcast_mut_unchecked < T : ' static > ( & mut self ) -> & mut T {
108
- mem:: transmute ( mem:: transmute :: < & mut NetworkStream ,
109
- raw:: TraitObject > ( self ) . data )
109
+ mem:: transmute ( traitobject:: data_mut ( self ) )
110
110
}
111
111
112
112
unsafe fn downcast_unchecked < T : ' static > ( self : Box < NetworkStream + Send > ) -> Box < T > {
113
- mem :: transmute ( mem:: transmute :: < Box < NetworkStream + Send > ,
114
- raw :: TraitObject > ( self ) . data )
113
+ let raw : * mut NetworkStream = mem:: transmute ( self ) ;
114
+ mem :: transmute ( traitobject :: data_mut ( raw ) )
115
115
}
116
116
}
117
117
118
118
impl NetworkStream + Send {
119
119
/// Is the underlying type in this trait object a T?
120
120
#[ inline]
121
- pub fn is < T : Reflect + ' static > ( & self ) -> bool {
122
- self . get_type_id ( ) == TypeId :: of :: < T > ( )
121
+ pub fn is < T : Any > ( & self ) -> bool {
122
+ ( * self ) . get_type ( ) == TypeId :: of :: < T > ( )
123
123
}
124
124
125
125
/// If the underlying type is T, get a reference to the contained data.
126
126
#[ inline]
127
- pub fn downcast_ref < T : Reflect + ' static > ( & self ) -> Option < & T > {
127
+ pub fn downcast_ref < T : Any > ( & self ) -> Option < & T > {
128
128
if self . is :: < T > ( ) {
129
129
Some ( unsafe { self . downcast_ref_unchecked ( ) } )
130
130
} else {
0 commit comments