diff options
| author | Marijn Haverbeke <[email protected]> | 2011-03-09 11:41:50 +0100 |
|---|---|---|
| committer | unknown <graydon@.(none)> | 2011-03-09 16:15:55 -0800 |
| commit | aed40fbcd8e81cc1ef7a51b40b76b4631cba299e (patch) | |
| tree | b9fe1cf0f40a6f54ab8b6522a3ed6677b127bb02 /src/lib/io.rs | |
| parent | Add stdout_writer and string_writer to std.io (diff) | |
| download | rust-aed40fbcd8e81cc1ef7a51b40b76b4631cba299e.tar.xz rust-aed40fbcd8e81cc1ef7a51b40b76b4631cba299e.zip | |
Have the pretty-printer take a writer stream as argument
It now uses a string writer to also fill in for
middle.ty.ast_ty_to_str
Diffstat (limited to 'src/lib/io.rs')
| -rw-r--r-- | src/lib/io.rs | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/lib/io.rs b/src/lib/io.rs index 71ebc1c7..dbe6de7a 100644 --- a/src/lib/io.rs +++ b/src/lib/io.rs @@ -91,26 +91,21 @@ tag fileflag { truncate; } -// FIXME move into fd_buf_writer -fn writefd(int fd, vec[u8] v) { - auto len = _vec.len[u8](v); - auto count = 0u; - auto vbuf; - while (count < len) { - vbuf = _vec.buf_off[u8](v, count); - auto nout = os.libc.write(fd, vbuf, len); - if (nout < 0) { - log "error dumping buffer"; - log sys.rustrt.last_os_error(); - fail; - } - count += nout as uint; - } -} - state obj fd_buf_writer(int fd, bool must_close) { fn write(vec[u8] v) { - writefd(fd, v); + auto len = _vec.len[u8](v); + auto count = 0u; + auto vbuf; + while (count < len) { + vbuf = _vec.buf_off[u8](v, count); + auto nout = os.libc.write(fd, vbuf, len); + if (nout < 0) { + log "error dumping buffer"; + log sys.rustrt.last_os_error(); + fail; + } + count += nout as uint; + } } drop { @@ -152,9 +147,15 @@ type writer = }; state obj new_writer(buf_writer out) { - impure fn write_str(str s) { out.write(_str.bytes(s)); } - impure fn write_int(int n) { out.write(_str.bytes(_int.to_str(n, 10u))); } - impure fn write_uint(uint n) { out.write(_str.bytes(_uint.to_str(n, 10u))); } + impure fn write_str(str s) { + out.write(_str.bytes(s)); + } + impure fn write_int(int n) { + out.write(_str.bytes(_int.to_str(n, 10u))); + } + impure fn write_uint(uint n) { + out.write(_str.bytes(_uint.to_str(n, 10u))); + } } fn file_writer(str path, vec[fileflag] flags) -> writer { |