@@ -14,30 +14,57 @@ use message::FrontendMessage::SslRequest;
1414
1515const DEFAULT_PORT : u16 = 5432 ;
1616
17- pub trait StreamWrapper < S : Read +Write > : Read +Write +Send {
18- fn get_ref ( & self ) -> & S ;
19- fn get_mut ( & mut self ) -> & mut S ;
17+ pub struct Stream ( InternalStream ) ;
18+
19+ impl Read for Stream {
20+ fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
21+ self . 0 . read ( buf)
22+ }
23+ }
24+
25+ impl Write for Stream {
26+ fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
27+ self . 0 . write ( buf)
28+ }
29+
30+ fn flush ( & mut self ) -> io:: Result < ( ) > {
31+ self . 0 . flush ( )
32+ }
33+ }
34+
35+ impl StreamWrapper for Stream {
36+ fn get_ref ( & self ) -> & Stream {
37+ self
38+ }
39+
40+ fn get_mut ( & mut self ) -> & mut Stream {
41+ self
42+ }
2043}
2144
22- impl < S : Read +Write +Send > StreamWrapper < S > for SslStream < S > {
23- fn get_ref ( & self ) -> & S {
45+ pub trait StreamWrapper : Read +Write +Send {
46+ fn get_ref ( & self ) -> & Stream ;
47+ fn get_mut ( & mut self ) -> & mut Stream ;
48+ }
49+
50+ impl StreamWrapper for SslStream < Stream > {
51+ fn get_ref ( & self ) -> & Stream {
2452 self . get_ref ( )
2553 }
2654
27- fn get_mut ( & mut self ) -> & mut S {
55+ fn get_mut ( & mut self ) -> & mut Stream {
2856 self . get_mut ( )
2957 }
3058}
3159
3260pub trait NegotiateSsl {
33- fn negotiate_ssl < S > ( & mut self , host : & str , stream : S )
34- -> Result < Box < StreamWrapper < S > > , Box < Error > >
35- where S : Read +Write +Send +' static ;
61+ fn negotiate_ssl ( & mut self , host : & str , stream : Stream )
62+ -> Result < Box < StreamWrapper > , Box < Error > > ;
3663}
3764
3865impl NegotiateSsl for SslContext {
39- fn negotiate_ssl < S > ( & mut self , _: & str , stream : S ) -> Result < Box < StreamWrapper < S > > , Box < Error > >
40- where S : Read + Write + Send + ' static {
66+ fn negotiate_ssl ( & mut self , _: & str , stream : Stream )
67+ -> Result < Box < StreamWrapper > , Box < Error > > {
4168 let stream = try!( SslStream :: new ( self , stream) ) ;
4269 Ok ( Box :: new ( stream) )
4370 }
@@ -56,8 +83,7 @@ pub enum SslMode<N = NoSsl> {
5683pub enum NoSsl { }
5784
5885impl NegotiateSsl for NoSsl {
59- fn negotiate_ssl < S : Read +Write > ( & mut self , _: & str , _: S )
60- -> Result < Box < StreamWrapper < S > > , Box < Error > > {
86+ fn negotiate_ssl ( & mut self , _: & str , _: Stream ) -> Result < Box < StreamWrapper > , Box < Error > > {
6187 match * self { }
6288 }
6389}
@@ -68,16 +94,6 @@ pub enum InternalStream {
6894 Unix ( UnixStream ) ,
6995}
7096
71- impl StreamWrapper < InternalStream > for InternalStream {
72- fn get_ref ( & self ) -> & InternalStream {
73- self
74- }
75-
76- fn get_mut ( & mut self ) -> & mut InternalStream {
77- self
78- }
79- }
80-
8197impl Read for InternalStream {
8298 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
8399 match * self {
@@ -122,9 +138,9 @@ fn open_socket(params: &ConnectParams) -> Result<InternalStream, ConnectError> {
122138}
123139
124140pub fn initialize_stream < N > ( params : & ConnectParams , ssl : & mut SslMode < N > )
125- -> Result < Box < StreamWrapper < InternalStream > > , ConnectError >
141+ -> Result < Box < StreamWrapper > , ConnectError >
126142 where N : NegotiateSsl {
127- let mut socket = try!( open_socket ( params) ) ;
143+ let mut socket = Stream ( try!( open_socket ( params) ) ) ;
128144
129145 let ( ssl_required, negotiator) = match * ssl {
130146 SslMode :: None => return Ok ( Box :: new ( socket) ) ,
0 commit comments