stdlib: Provide a function to extract the underlying buf_writer from a writer

This commit is contained in:
Patrick Walton 2011-03-22 17:52:03 -07:00
parent 23e23bd762
commit c1bc0101ca

View file

@ -223,6 +223,7 @@ fn file_buf_writer(str path, vec[fileflag] flags) -> buf_writer {
type writer =
state obj {
fn get_buf_writer() -> buf_writer;
impure fn write_str(str s);
impure fn write_int(int n);
impure fn write_uint(uint n);
@ -242,6 +243,9 @@ fn uint_to_le_bytes(uint n, uint size) -> vec[u8] {
}
state obj new_writer(buf_writer out) {
fn get_buf_writer() -> buf_writer {
ret out;
}
impure fn write_str(str s) {
out.write(_str.bytes(s));
}
@ -262,6 +266,11 @@ fn uint_to_le_bytes(uint n, uint size) -> vec[u8] {
}
}
// FIXME: Remove me once objects are exported.
fn new_writer_(buf_writer out) -> writer {
ret new_writer(out);
}
fn file_writer(str path, vec[fileflag] flags) -> writer {
ret new_writer(file_buf_writer(path, flags));
}