[src]

Struct std::io::RefWriter

pub struct RefWriter<'a, W> {
    inner: &'a mut W,
}

A RefWriter is a struct implementing Writer which contains a reference to another writer. This is often useful when composing streams.

Example

use std::io::util::TeeReader;
use std::io::{stdin, MemWriter};

let mut output = MemWriter::new();

{
    // Don't give ownership of 'output' to the 'tee'. Instead we keep a
    // handle to it in the outer scope
    let mut tee = TeeReader::new(stdin(), output.by_ref());
    process_input(tee);
}

println!("input processed: {}", output.unwrap());

Fields

inner

The underlying writer which this is referencing

Trait Implementations

impl<'a, W: Writer> Writer for RefWriter<'a, W>

fn write(&mut self, buf: &[u8]) -> IoResult<()>

Write the entirety of a given buffer

Errors

If an error happens during the I/O operation, the error is returned as Err. Note that it is considered an error if the entire buffer could not be written, and if an error is returned then it is unknown how much data (if any) was actually written.

fn flush(&mut self) -> IoResult<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination.

This is by default a no-op and implementers of the Writer trait should decide whether their stream needs to be buffered or not.

fn write_str(&mut self, s: &str) -> IoResult<()>

Write a rust string into this sink.

The bytes written will be the UTF-8 encoded version of the input string. If other encodings are desired, it is recommended to compose this stream with another performing the conversion, or to use write with a converted byte-array instead.

fn write_line(&mut self, s: &str) -> IoResult<()>

Writes a string into this sink, and then writes a literal newline (\n) byte afterwards. Note that the writing of the newline is not atomic in the sense that the call to write is invoked twice (once with the string and once with a newline character).

If other encodings or line ending flavors are desired, it is recommended that the write method is used specifically instead.

fn write_char(&mut self, c: char) -> IoResult<()>

Write a single char, encoded as UTF-8.

fn write_int(&mut self, n: int) -> IoResult<()>

Write the result of passing n through int::to_str_bytes.

fn write_uint(&mut self, n: uint) -> IoResult<()>

Write the result of passing n through uint::to_str_bytes.

fn write_le_uint(&mut self, n: uint) -> IoResult<()>

Write a little-endian uint (number of bytes depends on system).

fn write_le_int(&mut self, n: int) -> IoResult<()>

Write a little-endian int (number of bytes depends on system).

fn write_be_uint(&mut self, n: uint) -> IoResult<()>

Write a big-endian uint (number of bytes depends on system).

fn write_be_int(&mut self, n: int) -> IoResult<()>

Write a big-endian int (number of bytes depends on system).

fn write_be_u64(&mut self, n: u64) -> IoResult<()>

Write a big-endian u64 (8 bytes).

fn write_be_u32(&mut self, n: u32) -> IoResult<()>

Write a big-endian u32 (4 bytes).

fn write_be_u16(&mut self, n: u16) -> IoResult<()>

Write a big-endian u16 (2 bytes).

fn write_be_i64(&mut self, n: i64) -> IoResult<()>

Write a big-endian i64 (8 bytes).

fn write_be_i32(&mut self, n: i32) -> IoResult<()>

Write a big-endian i32 (4 bytes).

fn write_be_i16(&mut self, n: i16) -> IoResult<()>

Write a big-endian i16 (2 bytes).

fn write_be_f64(&mut self, f: f64) -> IoResult<()>

Write a big-endian IEEE754 double-precision floating-point (8 bytes).

fn write_be_f32(&mut self, f: f32) -> IoResult<()>

Write a big-endian IEEE754 single-precision floating-point (4 bytes).

fn write_le_u64(&mut self, n: u64) -> IoResult<()>

Write a little-endian u64 (8 bytes).

fn write_le_u32(&mut self, n: u32) -> IoResult<()>

Write a little-endian u32 (4 bytes).

fn write_le_u16(&mut self, n: u16) -> IoResult<()>

Write a little-endian u16 (2 bytes).

fn write_le_i64(&mut self, n: i64) -> IoResult<()>

Write a little-endian i64 (8 bytes).

fn write_le_i32(&mut self, n: i32) -> IoResult<()>

Write a little-endian i32 (4 bytes).

fn write_le_i16(&mut self, n: i16) -> IoResult<()>

Write a little-endian i16 (2 bytes).

fn write_le_f64(&mut self, f: f64) -> IoResult<()>

Write a little-endian IEEE754 double-precision floating-point (8 bytes).

fn write_le_f32(&mut self, f: f32) -> IoResult<()>

Write a little-endian IEEE754 single-precision floating-point (4 bytes).

fn write_u8(&mut self, n: u8) -> IoResult<()>

Write a u8 (1 byte).

fn write_i8(&mut self, n: i8) -> IoResult<()>

Write a i8 (1 byte).

fn by_ref<'a>(&'a mut self) -> RefWriter<'a, Self>

Creates a wrapper around a mutable reference to the writer.

This is useful to allow applying wrappers while still retaining ownership of the original value.