Change io.fileflag to a tag type. Remove FIXME

This commit is contained in:
Brian Anderson 2011-03-06 13:51:42 -05:00 committed by Graydon Hoare
parent 330c9c6c35
commit bed457d3a7
2 changed files with 9 additions and 20 deletions

View File

@ -85,18 +85,11 @@ fn new_buf_reader(str path) -> buf_reader {
ret fd_buf_reader(fd, new_buf());
}
/**
* FIXME (issue #150): This should be
*
* type fileflag = tag(append(), create(), truncate());
*
* but then the tag value ctors are not found from crate-importers of std, so
* we manually simulate the enum below.
*/
type fileflag = uint;
fn append() -> uint { ret 0u; }
fn create() -> uint { ret 1u; }
fn truncate() -> uint { ret 2u; }
tag fileflag {
append;
create;
truncate;
}
fn new_buf_writer(str path, vec[fileflag] flags) -> buf_writer {
@ -129,13 +122,9 @@ fn new_buf_writer(str path, vec[fileflag] flags) -> buf_writer {
for (fileflag f in flags) {
alt (f) {
// FIXME (issue #150): cf comment above defn of fileflag type
//case (append()) { fflags |= os.libc_constants.O_APPEND(); }
//case (create()) { fflags |= os.libc_constants.O_CREAT(); }
//case (truncate()) { fflags |= os.libc_constants.O_TRUNC(); }
case (0u) { fflags |= os.libc_constants.O_APPEND(); }
case (1u) { fflags |= os.libc_constants.O_CREAT(); }
case (2u) { fflags |= os.libc_constants.O_TRUNC(); }
case (append) { fflags |= os.libc_constants.O_APPEND(); }
case (create) { fflags |= os.libc_constants.O_CREAT(); }
case (truncate) { fflags |= os.libc_constants.O_TRUNC(); }
}
}

View File

@ -11,7 +11,7 @@ fn test_simple(str tmpfilebase) {
log frood;
{
let io.buf_writer out = io.new_buf_writer(tmpfile, vec(io.create()));
let io.buf_writer out = io.new_buf_writer(tmpfile, vec(io.create));
out.write(_str.bytes(frood));
}