Skip to content

Commit ed93d4f

Browse files
authored
Merge pull request #558 from rust-lang/lib-doc-update
Update `get_mut()` documentation to make clear how 'inner` can be used
2 parents fb5228d + a146d92 commit ed93d4f

9 files changed

Lines changed: 150 additions & 42 deletions

File tree

src/deflate/bufread.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ impl<R> DeflateEncoder<R> {
7878

7979
/// Acquires a mutable reference to the underlying stream
8080
///
81-
/// Note that mutation of the stream may result in surprising results if
82-
/// this encoder is continued to be used.
81+
/// The underlying reader may be mutated as long as its unread input and
82+
/// current position are preserved for subsequent reads by this encoder.
83+
///
84+
/// To process a new stream, wait for this encoder to reach EOF and use
85+
/// [`reset`](Self::reset); replacing the reader directly does not reset it.
8386
pub fn get_mut(&mut self) -> &mut R {
8487
&mut self.obj
8588
}
@@ -208,8 +211,11 @@ impl<R> DeflateDecoder<R> {
208211

209212
/// Acquires a mutable reference to the underlying stream
210213
///
211-
/// Note that mutation of the stream may result in surprising results if
212-
/// this decoder is continued to be used.
214+
/// The underlying reader may be mutated as long as its unread input and
215+
/// current position are preserved for subsequent reads by this decoder.
216+
///
217+
/// To process a new stream, wait for this decoder to reach EOF and use
218+
/// [`reset`](Self::reset); replacing the reader directly does not reset it.
213219
pub fn get_mut(&mut self) -> &mut R {
214220
&mut self.obj
215221
}

src/deflate/read.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@ impl<R> DeflateEncoder<R> {
7171

7272
/// Acquires a mutable reference to the underlying stream
7373
///
74-
/// Note that mutation of the stream may result in surprising results if
75-
/// this encoder is continued to be used.
74+
/// The underlying reader may be mutated as long as its unread input and
75+
/// current position are preserved for subsequent reads by this encoder.
76+
///
77+
/// To process a new stream, wait for this encoder to reach EOF and use
78+
/// [`reset`](Self::reset); replacing the reader directly does not reset it.
7679
pub fn get_mut(&mut self) -> &mut R {
7780
self.inner.get_mut().get_mut()
7881
}
@@ -202,8 +205,11 @@ impl<R> DeflateDecoder<R> {
202205

203206
/// Acquires a mutable reference to the underlying stream
204207
///
205-
/// Note that mutation of the stream may result in surprising results if
206-
/// this decoder is continued to be used.
208+
/// The underlying reader may be mutated as long as its unread input and
209+
/// current position are preserved for subsequent reads by this decoder.
210+
///
211+
/// To process a new stream, wait for this decoder to reach EOF and use
212+
/// [`reset`](Self::reset); replacing the reader directly does not reset it.
207213
pub fn get_mut(&mut self) -> &mut R {
208214
self.inner.get_mut().get_mut()
209215
}

src/deflate/write.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,18 @@ impl<W: Write> DeflateEncoder<W> {
5050

5151
/// Acquires a mutable reference to the underlying writer.
5252
///
53-
/// Note that mutating the output/input state of the stream may corrupt this
54-
/// object, so care must be taken when using this method.
53+
/// The underlying writer may be mutated or replaced as long as this
54+
/// preserves the bytes and ordering of the logical output stream.
55+
/// Concatenate output from each writer to reconstruct the complete stream.
56+
///
57+
/// Replacing the writer does not require [`flush`](Write::flush). Call it
58+
/// first when all input accepted so far must be decodable without output
59+
/// from later writes. This inserts a sync-flush point and changes the output
60+
/// bitstream. This is useful before applying [`std::mem::take`] to
61+
/// [`get_mut`](Self::get_mut) when forwarding the stream incrementally.
62+
///
63+
/// To start a new stream, use [`reset`](Self::reset); replacing the writer
64+
/// does not reset this encoder.
5565
pub fn get_mut(&mut self) -> &mut W {
5666
self.inner.get_mut()
5767
}
@@ -227,8 +237,17 @@ impl<W: Write> DeflateDecoder<W> {
227237

228238
/// Acquires a mutable reference to the underlying writer.
229239
///
230-
/// Note that mutating the output/input state of the stream may corrupt this
231-
/// object, so care must be taken when using this method.
240+
/// The underlying writer may be mutated or replaced as long as this
241+
/// preserves the bytes and ordering of the logical output stream.
242+
/// Concatenate output from each writer to reconstruct the complete stream.
243+
///
244+
/// Replacing the writer does not require [`flush`](Write::flush). Call it
245+
/// first to write all decompressed output currently available to the
246+
/// current writer. This is useful before applying [`std::mem::take`] to
247+
/// [`get_mut`](Self::get_mut) when forwarding output incrementally.
248+
///
249+
/// To start a new stream, use [`reset`](Self::reset); replacing the writer
250+
/// does not reset this decoder.
232251
pub fn get_mut(&mut self) -> &mut W {
233252
self.inner.get_mut()
234253
}

src/gz/bufread.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,11 @@ impl<R> GzEncoder<R> {
104104

105105
/// Acquires a mutable reference to the underlying reader.
106106
///
107-
/// Note that mutation of the reader may result in surprising results if
108-
/// this encoder is continued to be used.
107+
/// The underlying reader may be mutated as long as its unread input and
108+
/// current position are preserved for subsequent reads by this encoder.
109+
///
110+
/// To process a new stream, wait for this encoder to reach EOF and create a
111+
/// new encoder; replacing the reader directly does not reset it.
109112
pub fn get_mut(&mut self) -> &mut R {
110113
self.inner.get_mut().get_mut()
111114
}
@@ -273,8 +276,11 @@ impl<R> GzDecoder<R> {
273276

274277
/// Acquires a mutable reference to the underlying stream.
275278
///
276-
/// Note that mutation of the stream may result in surprising results if
277-
/// this decoder is continued to be used.
279+
/// The underlying reader may be mutated as long as its unread input and
280+
/// current position are preserved for subsequent reads by this decoder.
281+
///
282+
/// To process a new stream, wait for this decoder to reach EOF and use
283+
/// [`reset`](Self::reset); replacing the reader directly does not reset it.
278284
pub fn get_mut(&mut self) -> &mut R {
279285
self.reader.get_mut().get_mut()
280286
}
@@ -435,8 +441,11 @@ impl<R> MultiGzDecoder<R> {
435441

436442
/// Acquires a mutable reference to the underlying stream.
437443
///
438-
/// Note that mutation of the stream may result in surprising results if
439-
/// this decoder is continued to be used.
444+
/// The underlying reader may be mutated as long as its unread input and
445+
/// current position are preserved for subsequent reads by this decoder.
446+
///
447+
/// To process a new stream, wait for this decoder to reach EOF and create a
448+
/// new decoder; replacing the reader directly does not reset it.
440449
pub fn get_mut(&mut self) -> &mut R {
441450
self.0.get_mut()
442451
}

src/gz/read.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ impl<R> GzEncoder<R> {
6161

6262
/// Acquires a mutable reference to the underlying reader.
6363
///
64-
/// Note that mutation of the reader may result in surprising results if
65-
/// this encoder is continued to be used.
64+
/// The underlying reader may be mutated as long as its unread input and
65+
/// current position are preserved for subsequent reads by this encoder.
66+
///
67+
/// To process a new stream, wait for this encoder to reach EOF and create a
68+
/// new encoder; replacing the reader directly does not reset it.
6669
pub fn get_mut(&mut self) -> &mut R {
6770
self.inner.get_mut().get_mut()
6871
}
@@ -163,8 +166,11 @@ impl<R> GzDecoder<R> {
163166

164167
/// Acquires a mutable reference to the underlying stream.
165168
///
166-
/// Note that mutation of the stream may result in surprising results if
167-
/// this decoder continues to be used.
169+
/// The underlying reader may be mutated as long as its unread input and
170+
/// current position are preserved for subsequent reads by this decoder.
171+
///
172+
/// To process a new stream, wait for this decoder to reach EOF and use
173+
/// [`reset`](Self::reset); replacing the reader directly does not reset it.
168174
///
169175
/// Note that the decoder may have read past the end of the gzip data.
170176
/// To prevent this use [`bufread::GzDecoder`] instead.
@@ -283,8 +289,11 @@ impl<R> MultiGzDecoder<R> {
283289

284290
/// Acquires a mutable reference to the underlying stream.
285291
///
286-
/// Note that mutation of the stream may result in surprising results if
287-
/// this decoder is continued to be used.
292+
/// The underlying reader may be mutated as long as its unread input and
293+
/// current position are preserved for subsequent reads by this decoder.
294+
///
295+
/// To process a new stream, wait for this decoder to reach EOF and create a
296+
/// new decoder; replacing the reader directly does not reset it.
288297
pub fn get_mut(&mut self) -> &mut R {
289298
self.inner.get_mut().get_mut()
290299
}

src/gz/write.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,18 @@ impl<W: Write> GzEncoder<W> {
7878

7979
/// Acquires a mutable reference to the underlying writer.
8080
///
81-
/// Note that mutation of the writer may result in surprising results if
82-
/// this encoder is continued to be used.
81+
/// The underlying writer may be mutated or replaced as long as this
82+
/// preserves the bytes and ordering of the logical output stream.
83+
/// Concatenate output from each writer to reconstruct the complete stream.
84+
///
85+
/// Replacing the writer does not require [`flush`](Write::flush). Call it
86+
/// first when all input accepted so far must be decodable without output
87+
/// from later writes. This inserts a sync-flush point and changes the output
88+
/// bitstream. This is useful before applying [`std::mem::take`] to
89+
/// [`get_mut`](Self::get_mut) when forwarding the stream incrementally.
90+
///
91+
/// To start a new stream, call [`finish`](Self::finish) and create a new
92+
/// encoder; replacing the writer does not reset it.
8393
pub fn get_mut(&mut self) -> &mut W {
8494
self.inner.get_mut()
8595
}
@@ -254,8 +264,17 @@ impl<W: Write> GzDecoder<W> {
254264

255265
/// Acquires a mutable reference to the underlying writer.
256266
///
257-
/// Note that mutating the output/input state of the stream may corrupt this
258-
/// object, so care must be taken when using this method.
267+
/// The underlying writer may be mutated or replaced as long as this
268+
/// preserves the bytes and ordering of the logical output stream.
269+
/// Concatenate output from each writer to reconstruct the complete stream.
270+
///
271+
/// Replacing the writer does not require [`flush`](Write::flush). Call it
272+
/// first to write all decompressed output currently available to the
273+
/// current writer. This is useful before applying [`std::mem::take`] to
274+
/// [`get_mut`](Self::get_mut) when forwarding output incrementally.
275+
///
276+
/// To start a new stream, call [`finish`](Self::finish) and create a new
277+
/// decoder; replacing the writer does not reset it.
259278
pub fn get_mut(&mut self) -> &mut W {
260279
self.inner.get_mut().get_mut()
261280
}
@@ -408,8 +427,17 @@ impl<W: Write> MultiGzDecoder<W> {
408427

409428
/// Acquires a mutable reference to the underlying writer.
410429
///
411-
/// Note that mutating the output/input state of the stream may corrupt this
412-
/// object, so care must be taken when using this method.
430+
/// The underlying writer may be mutated or replaced as long as this
431+
/// preserves the bytes and ordering of the logical output stream.
432+
/// Concatenate output from each writer to reconstruct the complete stream.
433+
///
434+
/// Replacing the writer does not require [`flush`](Write::flush). Call it
435+
/// first to write all decompressed output currently available to the
436+
/// current writer. This is useful before applying [`std::mem::take`] to
437+
/// [`get_mut`](Self::get_mut) when forwarding output incrementally.
438+
///
439+
/// To start a new stream, call [`finish`](Self::finish) and create a new
440+
/// decoder; replacing the writer does not reset it.
413441
pub fn get_mut(&mut self) -> &mut W {
414442
self.inner.get_mut()
415443
}

src/zlib/bufread.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ impl<R> ZlibEncoder<R> {
8383

8484
/// Acquires a mutable reference to the underlying stream
8585
///
86-
/// Note that mutation of the stream may result in surprising results if
87-
/// this encoder is continued to be used.
86+
/// The underlying reader may be mutated as long as its unread input and
87+
/// current position are preserved for subsequent reads by this encoder.
88+
///
89+
/// To process a new stream, wait for this encoder to reach EOF and use
90+
/// [`reset`](Self::reset); replacing the reader directly does not reset it.
8891
pub fn get_mut(&mut self) -> &mut R {
8992
&mut self.obj
9093
}
@@ -216,8 +219,11 @@ impl<R> ZlibDecoder<R> {
216219

217220
/// Acquires a mutable reference to the underlying stream
218221
///
219-
/// Note that mutation of the stream may result in surprising results if
220-
/// this decoder is continued to be used.
222+
/// The underlying reader may be mutated as long as its unread input and
223+
/// current position are preserved for subsequent reads by this decoder.
224+
///
225+
/// To process a new stream, wait for this decoder to reach EOF and use
226+
/// [`reset`](Self::reset); replacing the reader directly does not reset it.
221227
pub fn get_mut(&mut self) -> &mut R {
222228
&mut self.obj
223229
}

src/zlib/read.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ impl<R> ZlibEncoder<R> {
7777

7878
/// Acquires a mutable reference to the underlying stream
7979
///
80-
/// Note that mutation of the stream may result in surprising results if
81-
/// this encoder is continued to be used.
80+
/// The underlying reader may be mutated as long as its unread input and
81+
/// current position are preserved for subsequent reads by this encoder.
82+
///
83+
/// To process a new stream, wait for this encoder to reach EOF and use
84+
/// [`reset`](Self::reset); replacing the reader directly does not reset it.
8285
pub fn get_mut(&mut self) -> &mut R {
8386
self.inner.get_mut().get_mut()
8487
}
@@ -236,8 +239,11 @@ impl<R> ZlibDecoder<R> {
236239

237240
/// Acquires a mutable reference to the underlying stream
238241
///
239-
/// Note that mutation of the stream may result in surprising results if
240-
/// this decoder is continued to be used.
242+
/// The underlying reader may be mutated as long as its unread input and
243+
/// current position are preserved for subsequent reads by this decoder.
244+
///
245+
/// To process a new stream, wait for this decoder to reach EOF and use
246+
/// [`reset`](Self::reset); replacing the reader directly does not reset it.
241247
pub fn get_mut(&mut self) -> &mut R {
242248
self.inner.get_mut().get_mut()
243249
}

src/zlib/write.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,18 @@ impl<W: Write> ZlibEncoder<W> {
5959

6060
/// Acquires a mutable reference to the underlying writer.
6161
///
62-
/// Note that mutating the output/input state of the stream may corrupt this
63-
/// object, so care must be taken when using this method.
62+
/// The underlying writer may be mutated or replaced as long as this
63+
/// preserves the bytes and ordering of the logical output stream.
64+
/// Concatenate output from each writer to reconstruct the complete stream.
65+
///
66+
/// Replacing the writer does not require [`flush`](Write::flush). Call it
67+
/// first when all input accepted so far must be decodable without output
68+
/// from later writes. This inserts a sync-flush point and changes the output
69+
/// bitstream. This is useful before applying [`std::mem::take`] to
70+
/// [`get_mut`](Self::get_mut) when forwarding the stream incrementally.
71+
///
72+
/// To start a new stream, use [`reset`](Self::reset); replacing the writer
73+
/// does not reset this encoder.
6474
pub fn get_mut(&mut self) -> &mut W {
6575
self.inner.get_mut()
6676
}
@@ -248,8 +258,17 @@ impl<W: Write> ZlibDecoder<W> {
248258

249259
/// Acquires a mutable reference to the underlying writer.
250260
///
251-
/// Note that mutating the output/input state of the stream may corrupt this
252-
/// object, so care must be taken when using this method.
261+
/// The underlying writer may be mutated or replaced as long as this
262+
/// preserves the bytes and ordering of the logical output stream.
263+
/// Concatenate output from each writer to reconstruct the complete stream.
264+
///
265+
/// Replacing the writer does not require [`flush`](Write::flush). Call it
266+
/// first to write all decompressed output currently available to the
267+
/// current writer. This is useful before applying [`std::mem::take`] to
268+
/// [`get_mut`](Self::get_mut) when forwarding output incrementally.
269+
///
270+
/// To start a new stream, use [`reset`](Self::reset); replacing the writer
271+
/// does not reset this decoder.
253272
pub fn get_mut(&mut self) -> &mut W {
254273
self.inner.get_mut()
255274
}

0 commit comments

Comments
 (0)