@@ -21,14 +21,13 @@ bitflags::bitflags! {
21
21
}
22
22
23
23
pin_project_lite:: pin_project! {
24
- /// A unified `Stream` and `Sink` interface to an underlying I/O object, using
25
- /// the `Encoder` and `Decoder` traits to encode and decode frames.
24
+ /// A unified `Stream` and `Sink` interface to an underlying I/O object, using the `Encoder` and
25
+ /// `Decoder` traits to encode and decode frames.
26
26
///
27
- /// Raw I/O objects work with byte sequences, but higher-level code usually
28
- /// wants to batch these into meaningful chunks, called "frames". This
29
- /// method layers framing on top of an I/O object, by using the `Encoder`/`Decoder`
30
- /// traits to handle encoding and decoding of message frames. Note that
31
- /// the incoming and outgoing frame types may be distinct.
27
+ /// Raw I/O objects work with byte sequences, but higher-level code usually wants to batch these
28
+ /// into meaningful chunks, called "frames". This method layers framing on top of an I/O object,
29
+ /// by using the `Encoder`/`Decoder` traits to handle encoding and decoding of message frames.
30
+ /// Note that the incoming and outgoing frame types may be distinct.
32
31
pub struct Framed <T , U > {
33
32
#[ pin]
34
33
io: T ,
44
43
T : AsyncRead + AsyncWrite ,
45
44
U : Decoder ,
46
45
{
47
- /// This function returns a *single* object that is both `Stream` and
48
- /// `Sink`; grouping this into a single object is often useful for layering
49
- /// things like gzip or TLS, which require both read and write access to the
50
- /// underlying object.
46
+ /// This function returns a *single* object that is both `Stream` and `Sink`; grouping this into
47
+ /// a single object is often useful for layering things like gzip or TLS, which require both
48
+ /// read and write access to the underlying object.
51
49
pub fn new ( io : T , codec : U ) -> Framed < T , U > {
52
50
Framed {
53
51
io,
@@ -70,21 +68,18 @@ impl<T, U> Framed<T, U> {
70
68
& mut self . codec
71
69
}
72
70
73
- /// Returns a reference to the underlying I/O stream wrapped by
74
- /// `Frame`.
71
+ /// Returns a reference to the underlying I/O stream wrapped by `Frame`.
75
72
///
76
- /// Note that care should be taken to not tamper with the underlying stream
77
- /// of data coming in as it may corrupt the stream of frames otherwise
78
- /// being worked with.
73
+ /// Note that care should be taken to not tamper with the underlying stream of data coming in as
74
+ /// it may corrupt the stream of frames otherwise being worked with.
79
75
pub fn io_ref ( & self ) -> & T {
80
76
& self . io
81
77
}
82
78
83
79
/// Returns a mutable reference to the underlying I/O stream.
84
80
///
85
- /// Note that care should be taken to not tamper with the underlying stream
86
- /// of data coming in as it may corrupt the stream of frames otherwise
87
- /// being worked with.
81
+ /// Note that care should be taken to not tamper with the underlying stream of data coming in as
82
+ /// it may corrupt the stream of frames otherwise being worked with.
88
83
pub fn io_mut ( & mut self ) -> & mut T {
89
84
& mut self . io
90
85
}
@@ -184,10 +179,9 @@ impl<T, U> Framed<T, U> {
184
179
{
185
180
loop {
186
181
let mut this = self . as_mut ( ) . project ( ) ;
187
- // Repeatedly call `decode` or `decode_eof` as long as it is
188
- // "readable". Readable is defined as not having returned `None`. If
189
- // the upstream has returned EOF, and the decoder is no longer
190
- // readable, it can be assumed that the decoder will never become
182
+ // Repeatedly call `decode` or `decode_eof` as long as it is "readable". Readable is
183
+ // defined as not having returned `None`. If the upstream has returned EOF, and the
184
+ // decoder is no longer readable, it can be assumed that the decoder will never become
191
185
// readable again, at which point the stream is terminated.
192
186
193
187
if this. flags . contains ( Flags :: READABLE ) {
@@ -215,7 +209,7 @@ impl<T, U> Framed<T, U> {
215
209
216
210
debug_assert ! ( !this. flags. contains( Flags :: EOF ) ) ;
217
211
218
- // Otherwise, try to read more data and try again. Make sure we've got room
212
+ // Otherwise, try to read more data and try again. Make sure we've got room.
219
213
let remaining = this. read_buf . capacity ( ) - this. read_buf . len ( ) ;
220
214
if remaining < LW {
221
215
this. read_buf . reserve ( HW - remaining)
@@ -341,13 +335,12 @@ where
341
335
}
342
336
343
337
impl < T , U > Framed < T , U > {
344
- /// This function returns a *single* object that is both `Stream` and
345
- /// `Sink`; grouping this into a single object is often useful for layering
346
- /// things like gzip or TLS, which require both read and write access to the
347
- /// underlying object.
338
+ /// This function returns a *single* object that is both `Stream` and `Sink`; grouping this into
339
+ /// a single object is often useful for layering things like gzip or TLS, which require both
340
+ /// read and write access to the underlying object.
348
341
///
349
- /// These objects take a stream, a read buffer and a write buffer. These
350
- /// fields can be obtained from an existing `Framed` with the `into_parts` method.
342
+ /// These objects take a stream, a read buffer and a write buffer. These fields can be obtained
343
+ /// from an existing `Framed` with the `into_parts` method.
351
344
pub fn from_parts ( parts : FramedParts < T , U > ) -> Framed < T , U > {
352
345
Framed {
353
346
io : parts. io ,
@@ -358,12 +351,11 @@ impl<T, U> Framed<T, U> {
358
351
}
359
352
}
360
353
361
- /// Consumes the `Frame`, returning its underlying I/O stream, the buffer
362
- /// with unprocessed data, and the codec.
354
+ /// Consumes the `Frame`, returning its underlying I/O stream, the buffer with unprocessed data,
355
+ /// and the codec.
363
356
///
364
- /// Note that care should be taken to not tamper with the underlying stream
365
- /// of data coming in as it may corrupt the stream of frames otherwise
366
- /// being worked with.
357
+ /// Note that care should be taken to not tamper with the underlying stream of data coming in as
358
+ /// it may corrupt the stream of frames otherwise being worked with.
367
359
pub fn into_parts ( self ) -> FramedParts < T , U > {
368
360
FramedParts {
369
361
io : self . io ,
@@ -376,14 +368,15 @@ impl<T, U> Framed<T, U> {
376
368
}
377
369
378
370
/// `FramedParts` contains an export of the data of a Framed transport.
379
- /// It can be used to construct a new `Framed` with a different codec.
380
- /// It contains all current buffers and the inner transport.
371
+ ///
372
+ /// It can be used to construct a new `Framed` with a different codec. It contains all current
373
+ /// buffers and the inner transport.
381
374
#[ derive( Debug ) ]
382
375
pub struct FramedParts < T , U > {
383
- /// The inner transport used to read bytes to and write bytes to
376
+ /// The inner transport used to read bytes to and write bytes to.
384
377
pub io : T ,
385
378
386
- /// The codec
379
+ /// The codec object.
387
380
pub codec : U ,
388
381
389
382
/// The buffer with read but unprocessed data.
@@ -396,7 +389,7 @@ pub struct FramedParts<T, U> {
396
389
}
397
390
398
391
impl < T , U > FramedParts < T , U > {
399
- /// Create a new, default, `FramedParts`
392
+ /// Creates a new default `FramedParts`.
400
393
pub fn new ( io : T , codec : U ) -> FramedParts < T , U > {
401
394
FramedParts {
402
395
io,
@@ -407,7 +400,7 @@ impl<T, U> FramedParts<T, U> {
407
400
}
408
401
}
409
402
410
- /// Create a new `FramedParts` with read buffer
403
+ /// Creates a new `FramedParts` with read buffer.
411
404
pub fn with_read_buf ( io : T , codec : U , read_buf : BytesMut ) -> FramedParts < T , U > {
412
405
FramedParts {
413
406
io,
0 commit comments