Skip to content

Commit 1e4efe2

Browse files
committed
Relax bounds for get_ref and get_mut
It should not be necessary to have S: Read + Write to get at references to S through TlsStream<S>, so this patch removes those bounds. This matters little in practice, since you likely can't construct a TlsStream on an S that isn't Read + Write, but it does mean that downstream crates that wrap TlsStream do not have to repeat the Read + Write bounds for _their_ get_ methods.
1 parent 3d138eb commit 1e4efe2

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

src/imp/openssl.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,17 @@ impl<S: fmt::Debug> fmt::Debug for TlsStream<S> {
332332
}
333333
}
334334

335-
impl<S: io::Read + io::Write> TlsStream<S> {
335+
impl<S> TlsStream<S> {
336336
pub fn get_ref(&self) -> &S {
337337
self.0.get_ref()
338338
}
339339

340340
pub fn get_mut(&mut self) -> &mut S {
341341
self.0.get_mut()
342342
}
343+
}
343344

345+
impl<S: io::Read + io::Write> TlsStream<S> {
344346
pub fn buffered_read_size(&self) -> Result<usize, Error> {
345347
Ok(self.0.ssl().pending())
346348
}

src/imp/schannel.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,20 @@ where
135135
}
136136
}
137137

138-
impl<S> MidHandshakeTlsStream<S>
139-
where
140-
S: io::Read + io::Write,
141-
{
138+
impl<S> MidHandshakeTlsStream<S> {
142139
pub fn get_ref(&self) -> &S {
143140
self.0.get_ref()
144141
}
145142

146143
pub fn get_mut(&mut self) -> &mut S {
147144
self.0.get_mut()
148145
}
146+
}
149147

148+
impl<S> MidHandshakeTlsStream<S>
149+
where
150+
S: io::Read + io::Write,
151+
{
150152
pub fn handshake(self) -> Result<TlsStream<S>, HandshakeError<S>> {
151153
match self.0.handshake() {
152154
Ok(s) => Ok(TlsStream(s)),
@@ -273,15 +275,17 @@ impl<S: fmt::Debug> fmt::Debug for TlsStream<S> {
273275
}
274276
}
275277

276-
impl<S: io::Read + io::Write> TlsStream<S> {
278+
impl<S> TlsStream<S> {
277279
pub fn get_ref(&self) -> &S {
278280
self.0.get_ref()
279281
}
280282

281283
pub fn get_mut(&mut self) -> &mut S {
282284
self.0.get_mut()
283285
}
286+
}
284287

288+
impl<S: io::Read + io::Write> TlsStream<S> {
285289
pub fn buffered_read_size(&self) -> Result<usize, Error> {
286290
Ok(self.0.get_buf().len())
287291
}

src/imp/security_framework.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,7 @@ where
218218
}
219219
}
220220

221-
impl<S> MidHandshakeTlsStream<S>
222-
where
223-
S: io::Read + io::Write,
224-
{
221+
impl<S> MidHandshakeTlsStream<S> {
225222
pub fn get_ref(&self) -> &S {
226223
match *self {
227224
MidHandshakeTlsStream::Server(ref s, _) => s.get_ref(),
@@ -235,7 +232,12 @@ where
235232
MidHandshakeTlsStream::Client(ref mut s) => s.get_mut(),
236233
}
237234
}
235+
}
238236

237+
impl<S> MidHandshakeTlsStream<S>
238+
where
239+
S: io::Read + io::Write,
240+
{
239241
pub fn handshake(self) -> Result<TlsStream<S>, HandshakeError<S>> {
240242
match self {
241243
MidHandshakeTlsStream::Server(s, cert) => match s.handshake() {
@@ -362,15 +364,17 @@ impl<S: fmt::Debug> fmt::Debug for TlsStream<S> {
362364
}
363365
}
364366

365-
impl<S: io::Read + io::Write> TlsStream<S> {
367+
impl<S> TlsStream<S> {
366368
pub fn get_ref(&self) -> &S {
367369
self.stream.get_ref()
368370
}
369371

370372
pub fn get_mut(&mut self) -> &mut S {
371373
self.stream.get_mut()
372374
}
375+
}
373376

377+
impl<S: io::Read + io::Write> TlsStream<S> {
374378
pub fn buffered_read_size(&self) -> Result<usize, Error> {
375379
Ok(self.stream.context().buffered_read_size()?)
376380
}

src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,7 @@ where
220220
}
221221
}
222222

223-
impl<S> MidHandshakeTlsStream<S>
224-
where
225-
S: io::Read + io::Write,
226-
{
223+
impl<S> MidHandshakeTlsStream<S> {
227224
/// Returns a shared reference to the inner stream.
228225
pub fn get_ref(&self) -> &S {
229226
self.0.get_ref()
@@ -233,7 +230,12 @@ where
233230
pub fn get_mut(&mut self) -> &mut S {
234231
self.0.get_mut()
235232
}
233+
}
236234

235+
impl<S> MidHandshakeTlsStream<S>
236+
where
237+
S: io::Read + io::Write,
238+
{
237239
/// Restarts the handshake process.
238240
///
239241
/// If the handshake completes successfully then the negotiated stream is
@@ -608,7 +610,7 @@ impl<S: fmt::Debug> fmt::Debug for TlsStream<S> {
608610
}
609611
}
610612

611-
impl<S: io::Read + io::Write> TlsStream<S> {
613+
impl<S> TlsStream<S> {
612614
/// Returns a shared reference to the inner stream.
613615
pub fn get_ref(&self) -> &S {
614616
self.0.get_ref()
@@ -618,7 +620,9 @@ impl<S: io::Read + io::Write> TlsStream<S> {
618620
pub fn get_mut(&mut self) -> &mut S {
619621
self.0.get_mut()
620622
}
623+
}
621624

625+
impl<S: io::Read + io::Write> TlsStream<S> {
622626
/// Returns the number of bytes that can be read without resulting in any
623627
/// network calls.
624628
pub fn buffered_read_size(&self) -> Result<usize> {

0 commit comments

Comments
 (0)