(index<- ) ./libstd/io/buffered.rs
git branch: * master 5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
modified: Fri May 9 13:02:28 2014
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Buffering wrappers for I/O traits
12
13 use cmp;
14 use container::Container;
15 use io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult};
16 use iter::ExactSize;
17 use ops::Drop;
18 use option::{Some, None, Option};
19 use result::{Ok, Err, ResultUnwrap};
20 use slice::{ImmutableVector, MutableVector};
21 use slice;
22 use vec::Vec;
23
24 /// Wraps a Reader and buffers input from it
25 ///
26 /// It can be excessively inefficient to work directly with a `Reader`. For
27 /// example, every call to `read` on `TcpStream` results in a system call. A
28 /// `BufferedReader` performs large, infrequent reads on the underlying
29 /// `Reader` and maintains an in-memory buffer of the results.
30 ///
31 /// # Example
32 ///
33 /// ```rust
34 /// use std::io::{BufferedReader, File};
35 ///
36 /// let file = File::open(&Path::new("message.txt"));
37 /// let mut reader = BufferedReader::new(file);
38 ///
39 /// let mut buf = [0, ..100];
40 /// match reader.read(buf) {
41 /// Ok(nread) => println!("Read {} bytes", nread),
42 /// Err(e) => println!("error reading: {}", e)
43 /// }
44 /// ```
45 pub struct BufferedReader<R> {
46 inner: R,
47 buf: Vec<u8>,
48 pos: uint,
49 cap: uint,
50 }
51
52 impl<R: Reader> BufferedReader<R> {
53 /// Creates a new `BufferedReader` with the specified buffer capacity
54 pub fn with_capacity(cap: uint, inner: R) -> BufferedReader<R> {
55 // It's *much* faster to create an uninitialized buffer than it is to
56 // fill everything in with 0. This buffer is entirely an implementation
57 // detail and is never exposed, so we're safe to not initialize
58 // everything up-front. This allows creation of BufferedReader instances
59 // to be very cheap (large mallocs are not nearly as expensive as large
60 // callocs).
61 let mut buf = Vec::with_capacity(cap);
62 unsafe { buf.set_len(cap); }
63 BufferedReader {
64 inner: inner,
65 buf: buf,
66 pos: 0,
67 cap: 0,
68 }
69 }
70
71 /// Creates a new `BufferedReader` with a default buffer capacity
72 pub fn new(inner: R) -> BufferedReader<R> {
73 BufferedReader::with_capacity(DEFAULT_BUF_SIZE, inner)
74 }
75
76 /// Gets a reference to the underlying reader.
77 ///
78 /// This type does not expose the ability to get a mutable reference to the
79 /// underlying reader because that could possibly corrupt the buffer.
80 pub fn get_ref<'a>(&'a self) -> &'a R { &self.inner }
81
82 /// Unwraps this `BufferedReader`, returning the underlying reader.
83 ///
84 /// Note that any leftover data in the internal buffer is lost.
85 pub fn unwrap(self) -> R { self.inner }
86 }
87
88 impl<R: Reader> Buffer for BufferedReader<R> {
89 fn fill_buf<'a>(&'a mut self) -> IoResult<&'a [u8]> {
90 if self.pos == self.cap {
91 self.cap = try!(self.inner.read(self.buf.as_mut_slice()));
92 self.pos = 0;
93 }
94 Ok(self.buf.slice(self.pos, self.cap))
95 }
96
97 fn consume(&mut self, amt: uint) {
98 self.pos += amt;
99 assert!(self.pos <= self.cap);
100 }
101 }
102
103 impl<R: Reader> Reader for BufferedReader<R> {
104 fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
105 let nread = {
106 let available = try!(self.fill_buf());
107 let nread = cmp::min(available.len(), buf.len());
108 slice::bytes::copy_memory(buf, available.slice_to(nread));
109 nread
110 };
111 self.pos += nread;
112 Ok(nread)
113 }
114 }
115
116 /// Wraps a Writer and buffers output to it
117 ///
118 /// It can be excessively inefficient to work directly with a `Writer`. For
119 /// example, every call to `write` on `TcpStream` results in a system call. A
120 /// `BufferedWriter` keeps an in memory buffer of data and writes it to the
121 /// underlying `Writer` in large, infrequent batches.
122 ///
123 /// This writer will be flushed when it is dropped.
124 ///
125 /// # Example
126 ///
127 /// ```rust
128 /// # #![allow(unused_must_use)]
129 /// use std::io::{BufferedWriter, File};
130 ///
131 /// let file = File::open(&Path::new("message.txt"));
132 /// let mut writer = BufferedWriter::new(file);
133 ///
134 /// writer.write_str("hello, world");
135 /// writer.flush();
136 /// ```
137 pub struct BufferedWriter<W> {
138 inner: Option<W>,
139 buf: Vec<u8>,
140 pos: uint
141 }
142
143 impl<W: Writer> BufferedWriter<W> {
144 /// Creates a new `BufferedWriter` with the specified buffer capacity
145 pub fn with_capacity(cap: uint, inner: W) -> BufferedWriter<W> {
146 // See comments in BufferedReader for why this uses unsafe code.
147 let mut buf = Vec::with_capacity(cap);
148 unsafe { buf.set_len(cap); }
149 BufferedWriter {
150 inner: Some(inner),
151 buf: buf,
152 pos: 0
153 }
154 }
155
156 /// Creates a new `BufferedWriter` with a default buffer capacity
157 pub fn new(inner: W) -> BufferedWriter<W> {
158 BufferedWriter::with_capacity(DEFAULT_BUF_SIZE, inner)
159 }
160
161 fn flush_buf(&mut self) -> IoResult<()> {
162 if self.pos != 0 {
163 let ret = self.inner.get_mut_ref().write(self.buf.slice_to(self.pos));
164 self.pos = 0;
165 ret
166 } else {
167 Ok(())
168 }
169 }
170
171 /// Gets a reference to the underlying writer.
172 ///
173 /// This type does not expose the ability to get a mutable reference to the
174 /// underlying reader because that could possibly corrupt the buffer.
175 pub fn get_ref<'a>(&'a self) -> &'a W { self.inner.get_ref() }
176
177 /// Unwraps this `BufferedWriter`, returning the underlying writer.
178 ///
179 /// The buffer is flushed before returning the writer.
180 pub fn unwrap(mut self) -> W {
181 // FIXME(#12628): is failing the right thing to do if flushing fails?
182 self.flush_buf().unwrap();
183 self.inner.take_unwrap()
184 }
185 }
186
187 impl<W: Writer> Writer for BufferedWriter<W> {
188 fn write(&mut self, buf: &[u8]) -> IoResult<()> {
189 if self.pos + buf.len() > self.buf.len() {
190 try!(self.flush_buf());
191 }
192
193 if buf.len() > self.buf.len() {
194 self.inner.get_mut_ref().write(buf)
195 } else {
196 let dst = self.buf.mut_slice_from(self.pos);
197 slice::bytes::copy_memory(dst, buf);
198 self.pos += buf.len();
199 Ok(())
200 }
201 }
202
203 fn flush(&mut self) -> IoResult<()> {
204 self.flush_buf().and_then(|()| self.inner.get_mut_ref().flush())
205 }
206 }
207
208 #[unsafe_destructor]
209 impl<W: Writer> Drop for BufferedWriter<W> {
210 fn drop(&mut self) {
211 if self.inner.is_some() {
212 // FIXME(#12628): should this error be ignored?
213 let _ = self.flush_buf();
214 }
215 }
216 }
217
218 /// Wraps a Writer and buffers output to it, flushing whenever a newline (`0x0a`,
219 /// `'\n'`) is detected.
220 ///
221 /// This writer will be flushed when it is dropped.
222 pub struct LineBufferedWriter<W> {
223 inner: BufferedWriter<W>,
224 }
225
226 impl<W: Writer> LineBufferedWriter<W> {
227 /// Creates a new `LineBufferedWriter`
228 pub fn new(inner: W) -> LineBufferedWriter<W> {
229 // Lines typically aren't that long, don't use a giant buffer
230 LineBufferedWriter {
231 inner: BufferedWriter::with_capacity(1024, inner)
232 }
233 }
234
235 /// Gets a reference to the underlying writer.
236 ///
237 /// This type does not expose the ability to get a mutable reference to the
238 /// underlying reader because that could possibly corrupt the buffer.
239 pub fn get_ref<'a>(&'a self) -> &'a W { self.inner.get_ref() }
240
241 /// Unwraps this `LineBufferedWriter`, returning the underlying writer.
242 ///
243 /// The internal buffer is flushed before returning the writer.
244 pub fn unwrap(self) -> W { self.inner.unwrap() }
245 }
246
247 impl<W: Writer> Writer for LineBufferedWriter<W> {
248 fn write(&mut self, buf: &[u8]) -> IoResult<()> {
249 match buf.iter().rposition(|&b| b == '\n' as u8) {
250 Some(i) => {
251 try!(self.inner.write(buf.slice_to(i + 1)));
252 try!(self.inner.flush());
253 try!(self.inner.write(buf.slice_from(i + 1)));
254 Ok(())
255 }
256 None => self.inner.write(buf),
257 }
258 }
259
260 fn flush(&mut self) -> IoResult<()> { self.inner.flush() }
261 }
262
263 struct InternalBufferedWriter<W>(BufferedWriter<W>);
264
265 impl<W> InternalBufferedWriter<W> {
266 fn get_mut_ref<'a>(&'a mut self) -> &'a mut BufferedWriter<W> {
267 let InternalBufferedWriter(ref mut w) = *self;
268 return w;
269 }
270 }
271
272 impl<W: Reader> Reader for InternalBufferedWriter<W> {
273 fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
274 self.get_mut_ref().inner.get_mut_ref().read(buf)
275 }
276 }
277
278 /// Wraps a Stream and buffers input and output to and from it.
279 ///
280 /// It can be excessively inefficient to work directly with a `Stream`. For
281 /// example, every call to `read` or `write` on `TcpStream` results in a system
282 /// call. A `BufferedStream` keeps in memory buffers of data, making large,
283 /// infrequent calls to `read` and `write` on the underlying `Stream`.
284 ///
285 /// The output half will be flushed when this stream is dropped.
286 ///
287 /// # Example
288 ///
289 /// ```rust
290 /// # #![allow(unused_must_use)]
291 /// use std::io::{BufferedStream, File};
292 ///
293 /// let file = File::open(&Path::new("message.txt"));
294 /// let mut stream = BufferedStream::new(file);
295 ///
296 /// stream.write("hello, world".as_bytes());
297 /// stream.flush();
298 ///
299 /// let mut buf = [0, ..100];
300 /// match stream.read(buf) {
301 /// Ok(nread) => println!("Read {} bytes", nread),
302 /// Err(e) => println!("error reading: {}", e)
303 /// }
304 /// ```
305 pub struct BufferedStream<S> {
306 inner: BufferedReader<InternalBufferedWriter<S>>
307 }
308
309 impl<S: Stream> BufferedStream<S> {
310 /// Creates a new buffered stream with explicitly listed capacities for the
311 /// reader/writer buffer.
312 pub fn with_capacities(reader_cap: uint, writer_cap: uint, inner: S)
313 -> BufferedStream<S> {
314 let writer = BufferedWriter::with_capacity(writer_cap, inner);
315 let internal_writer = InternalBufferedWriter(writer);
316 let reader = BufferedReader::with_capacity(reader_cap,
317 internal_writer);
318 BufferedStream { inner: reader }
319 }
320
321 /// Creates a new buffered stream with the default reader/writer buffer
322 /// capacities.
323 pub fn new(inner: S) -> BufferedStream<S> {
324 BufferedStream::with_capacities(DEFAULT_BUF_SIZE, DEFAULT_BUF_SIZE,
325 inner)
326 }
327
328 /// Gets a reference to the underlying stream.
329 ///
330 /// This type does not expose the ability to get a mutable reference to the
331 /// underlying reader because that could possibly corrupt the buffer.
332 pub fn get_ref<'a>(&'a self) -> &'a S {
333 let InternalBufferedWriter(ref w) = self.inner.inner;
334 w.get_ref()
335 }
336
337 /// Unwraps this `BufferedStream`, returning the underlying stream.
338 ///
339 /// The internal buffer is flushed before returning the stream. Any leftover
340 /// data in the read buffer is lost.
341 pub fn unwrap(self) -> S {
342 let InternalBufferedWriter(w) = self.inner.inner;
343 w.unwrap()
344 }
345 }
346
347 impl<S: Stream> Buffer for BufferedStream<S> {
348 fn fill_buf<'a>(&'a mut self) -> IoResult<&'a [u8]> { self.inner.fill_buf() }
349 fn consume(&mut self, amt: uint) { self.inner.consume(amt) }
350 }
351
352 impl<S: Stream> Reader for BufferedStream<S> {
353 fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
354 self.inner.read(buf)
355 }
356 }
357
358 impl<S: Stream> Writer for BufferedStream<S> {
359 fn write(&mut self, buf: &[u8]) -> IoResult<()> {
360 self.inner.inner.get_mut_ref().write(buf)
361 }
362 fn flush(&mut self) -> IoResult<()> {
363 self.inner.inner.get_mut_ref().flush()
364 }
365 }
366
367 #[cfg(test)]
368 mod test {
369 extern crate test;
370 use io;
371 use prelude::*;
372 use super::*;
373 use super::super::mem::{MemReader, MemWriter, BufReader};
374 use self::test::Bencher;
375 use str::StrSlice;
376
377 /// A type, free to create, primarily intended for benchmarking creation of
378 /// wrappers that, just for construction, don't need a Reader/Writer that
379 /// does anything useful. Is equivalent to `/dev/null` in semantics.
380 #[deriving(Clone,Eq,Ord)]
381 pub struct NullStream;
382
383 impl Reader for NullStream {
384 fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> {
385 Err(io::standard_error(io::EndOfFile))
386 }
387 }
388
389 impl Writer for NullStream {
390 fn write(&mut self, _: &[u8]) -> io::IoResult<()> { Ok(()) }
391 }
392
393 /// A dummy reader intended at testing short-reads propagation.
394 pub struct ShortReader {
395 lengths: Vec<uint>,
396 }
397
398 impl Reader for ShortReader {
399 fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> {
400 match self.lengths.shift() {
401 Some(i) => Ok(i),
402 None => Err(io::standard_error(io::EndOfFile))
403 }
404 }
405 }
406
407 #[test]
408 fn test_buffered_reader() {
409 let inner = MemReader::new(vec!(0, 1, 2, 3, 4));
410 let mut reader = BufferedReader::with_capacity(2, inner);
411
412 let mut buf = [0, 0, 0];
413 let nread = reader.read(buf);
414 assert_eq!(Ok(2), nread);
415 assert_eq!(buf.as_slice(), &[0, 1, 0]);
416
417 let mut buf = [0];
418 let nread = reader.read(buf);
419 assert_eq!(Ok(1), nread);
420 assert_eq!(buf.as_slice(), &[2]);
421
422 let mut buf = [0, 0, 0];
423 let nread = reader.read(buf);
424 assert_eq!(Ok(1), nread);
425 assert_eq!(buf.as_slice(), &[3, 0, 0]);
426
427 let nread = reader.read(buf);
428 assert_eq!(Ok(1), nread);
429 assert_eq!(buf.as_slice(), &[4, 0, 0]);
430
431 assert!(reader.read(buf).is_err());
432 }
433
434 #[test]
435 fn test_buffered_writer() {
436 let inner = MemWriter::new();
437 let mut writer = BufferedWriter::with_capacity(2, inner);
438
439 writer.write([0, 1]).unwrap();
440 assert_eq!(writer.get_ref().get_ref(), &[]);
441
442 writer.write([2]).unwrap();
443 assert_eq!(writer.get_ref().get_ref(), &[0, 1]);
444
445 writer.write([3]).unwrap();
446 assert_eq!(writer.get_ref().get_ref(), &[0, 1]);
447
448 writer.flush().unwrap();
449 assert_eq!(&[0, 1, 2, 3], writer.get_ref().get_ref());
450
451 writer.write([4]).unwrap();
452 writer.write([5]).unwrap();
453 assert_eq!(&[0, 1, 2, 3], writer.get_ref().get_ref());
454
455 writer.write([6]).unwrap();
456 assert_eq!(&[0, 1, 2, 3, 4, 5],
457 writer.get_ref().get_ref());
458
459 writer.write([7, 8]).unwrap();
460 assert_eq!(&[0, 1, 2, 3, 4, 5, 6],
461 writer.get_ref().get_ref());
462
463 writer.write([9, 10, 11]).unwrap();
464 assert_eq!(&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
465 writer.get_ref().get_ref());
466
467 writer.flush().unwrap();
468 assert_eq!(&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
469 writer.get_ref().get_ref());
470 }
471
472 #[test]
473 fn test_buffered_writer_inner_flushes() {
474 let mut w = BufferedWriter::with_capacity(3, MemWriter::new());
475 w.write([0, 1]).unwrap();
476 assert_eq!(&[], w.get_ref().get_ref());
477 let w = w.unwrap();
478 assert_eq!(&[0, 1], w.get_ref());
479 }
480
481 // This is just here to make sure that we don't infinite loop in the
482 // newtype struct autoderef weirdness
483 #[test]
484 fn test_buffered_stream() {
485 struct S;
486
487 impl io::Writer for S {
488 fn write(&mut self, _: &[u8]) -> io::IoResult<()> { Ok(()) }
489 }
490
491 impl io::Reader for S {
492 fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> {
493 Err(io::standard_error(io::EndOfFile))
494 }
495 }
496
497 let mut stream = BufferedStream::new(S);
498 let mut buf = [];
499 assert!(stream.read(buf).is_err());
500 stream.write(buf).unwrap();
501 stream.flush().unwrap();
502 }
503
504 #[test]
505 fn test_read_until() {
506 let inner = MemReader::new(vec!(0, 1, 2, 1, 0));
507 let mut reader = BufferedReader::with_capacity(2, inner);
508 assert_eq!(reader.read_until(0), Ok(vec!(0)));
509 assert_eq!(reader.read_until(2), Ok(vec!(1, 2)));
510 assert_eq!(reader.read_until(1), Ok(vec!(1)));
511 assert_eq!(reader.read_until(8), Ok(vec!(0)));
512 assert!(reader.read_until(9).is_err());
513 }
514
515 #[test]
516 fn test_line_buffer() {
517 let mut writer = LineBufferedWriter::new(MemWriter::new());
518 writer.write([0]).unwrap();
519 assert_eq!(writer.get_ref().get_ref(), &[]);
520 writer.write([1]).unwrap();
521 assert_eq!(writer.get_ref().get_ref(), &[]);
522 writer.flush().unwrap();
523 assert_eq!(writer.get_ref().get_ref(), &[0, 1]);
524 writer.write([0, '\n' as u8, 1, '\n' as u8, 2]).unwrap();
525 assert_eq!(writer.get_ref().get_ref(),
526 &[0, 1, 0, '\n' as u8, 1, '\n' as u8]);
527 writer.flush().unwrap();
528 assert_eq!(writer.get_ref().get_ref(),
529 &[0, 1, 0, '\n' as u8, 1, '\n' as u8, 2]);
530 writer.write([3, '\n' as u8]).unwrap();
531 assert_eq!(writer.get_ref().get_ref(),
532 &[0, 1, 0, '\n' as u8, 1, '\n' as u8, 2, 3, '\n' as u8]);
533 }
534
535 #[test]
536 fn test_read_line() {
537 let in_buf = MemReader::new(Vec::from_slice(bytes!("a\nb\nc")));
538 let mut reader = BufferedReader::with_capacity(2, in_buf);
539 assert_eq!(reader.read_line(), Ok("a\n".to_owned()));
540 assert_eq!(reader.read_line(), Ok("b\n".to_owned()));
541 assert_eq!(reader.read_line(), Ok("c".to_owned()));
542 assert!(reader.read_line().is_err());
543 }
544
545 #[test]
546 fn test_lines() {
547 let in_buf = MemReader::new(Vec::from_slice(bytes!("a\nb\nc")));
548 let mut reader = BufferedReader::with_capacity(2, in_buf);
549 let mut it = reader.lines();
550 assert_eq!(it.next(), Some(Ok("a\n".to_owned())));
551 assert_eq!(it.next(), Some(Ok("b\n".to_owned())));
552 assert_eq!(it.next(), Some(Ok("c".to_owned())));
553 assert_eq!(it.next(), None);
554 }
555
556 #[test]
557 fn test_short_reads() {
558 let inner = ShortReader{lengths: vec![0, 1, 2, 0, 1, 0]};
559 let mut reader = BufferedReader::new(inner);
560 let mut buf = [0, 0];
561 assert_eq!(reader.read(buf), Ok(0));
562 assert_eq!(reader.read(buf), Ok(1));
563 assert_eq!(reader.read(buf), Ok(2));
564 assert_eq!(reader.read(buf), Ok(0));
565 assert_eq!(reader.read(buf), Ok(1));
566 assert_eq!(reader.read(buf), Ok(0));
567 assert!(reader.read(buf).is_err());
568 }
569
570 #[test]
571 fn read_char_buffered() {
572 let buf = [195u8, 159u8];
573 let mut reader = BufferedReader::with_capacity(1, BufReader::new(buf));
574 assert_eq!(reader.read_char(), Ok('Ã'));
575 }
576
577 #[test]
578 fn test_chars() {
579 let buf = [195u8, 159u8, 'a' as u8];
580 let mut reader = BufferedReader::with_capacity(1, BufReader::new(buf));
581 let mut it = reader.chars();
582 assert_eq!(it.next(), Some(Ok('Ã')));
583 assert_eq!(it.next(), Some(Ok('a')));
584 assert_eq!(it.next(), None);
585 }
586
587 #[bench]
588 fn bench_buffered_reader(b: &mut Bencher) {
589 b.iter(|| {
590 BufferedReader::new(NullStream)
591 });
592 }
593
594 #[bench]
595 fn bench_buffered_writer(b: &mut Bencher) {
596 b.iter(|| {
597 BufferedWriter::new(NullStream)
598 });
599 }
600
601 #[bench]
602 fn bench_buffered_stream(b: &mut Bencher) {
603 b.iter(|| {
604 BufferedStream::new(NullStream);
605 });
606 }
607 }
libstd/io/buffered.rs:304:8-304:8 -struct- definition:
/// ```
pub struct BufferedStream<S> {
inner: BufferedReader<InternalBufferedWriter<S>>
references:- 7317: internal_writer);
318: BufferedStream { inner: reader }
319: }
--
358: impl<S: Stream> Writer for BufferedStream<S> {
359: fn write(&mut self, buf: &[u8]) -> IoResult<()> {
libstd/io/buffered.rs:221:52-221:52 -struct- definition:
/// This writer will be flushed when it is dropped.
pub struct LineBufferedWriter<W> {
inner: BufferedWriter<W>,
references:- 6229: // Lines typically aren't that long, don't use a giant buffer
230: LineBufferedWriter {
231: inner: BufferedWriter::with_capacity(1024, inner)
--
247: impl<W: Writer> Writer for LineBufferedWriter<W> {
248: fn write(&mut self, buf: &[u8]) -> IoResult<()> {
libstd/io/stdio.rs:
145: /// See `stdout()` for notes about this function.
146: pub fn stderr() -> LineBufferedWriter<StdWriter> {
147: LineBufferedWriter::new(stderr_raw())
libstd/io/buffered.rs:
226: impl<W: Writer> LineBufferedWriter<W> {
227: /// Creates a new `LineBufferedWriter`
libstd/io/buffered.rs:262:1-262:1 -struct- definition:
struct InternalBufferedWriter<W>(BufferedWriter<W>);
impl<W> InternalBufferedWriter<W> {
fn get_mut_ref<'a>(&'a mut self) -> &'a mut BufferedWriter<W> {
references:- 3265: impl<W> InternalBufferedWriter<W> {
266: fn get_mut_ref<'a>(&'a mut self) -> &'a mut BufferedWriter<W> {
--
305: pub struct BufferedStream<S> {
306: inner: BufferedReader<InternalBufferedWriter<S>>
307: }
libstd/io/buffered.rs:44:8-44:8 -struct- definition:
/// ```
pub struct BufferedReader<R> {
inner: R,
references:- 8103: impl<R: Reader> Reader for BufferedReader<R> {
104: fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
--
305: pub struct BufferedStream<S> {
306: inner: BufferedReader<InternalBufferedWriter<S>>
307: }
libstd/io/stdio.rs:
100: /// See `stdout()` for more notes about this function.
101: pub fn stdin() -> BufferedReader<StdReader> {
102: // The default buffer capacity is 64k, but apparently windows doesn't like
libstd/io/buffered.rs:
62: unsafe { buf.set_len(cap); }
63: BufferedReader {
64: inner: inner,
libstd/io/buffered.rs:136:8-136:8 -struct- definition:
/// ```
pub struct BufferedWriter<W> {
inner: Option<W>,
references:- 9148: unsafe { buf.set_len(cap); }
149: BufferedWriter {
150: inner: Some(inner),
--
187: impl<W: Writer> Writer for BufferedWriter<W> {
188: fn write(&mut self, buf: &[u8]) -> IoResult<()> {
--
265: impl<W> InternalBufferedWriter<W> {
266: fn get_mut_ref<'a>(&'a mut self) -> &'a mut BufferedWriter<W> {
267: let InternalBufferedWriter(ref mut w) = *self;