Skip to content

Commit

Permalink
Make with_bytes_reader/with_bytes_writer pure
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Oct 18, 2012
1 parent 4e03ffd commit b18a151
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/libcore/dvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum DVec<A> {
}

/// Creates a new, empty dvec
pub fn DVec<A>() -> DVec<A> {
pub pure fn DVec<A>() -> DVec<A> {
DVec_({mut data: ~[]})
}

Expand Down
18 changes: 11 additions & 7 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl ByteBuf: Reader {
fn tell() -> uint { self.pos }
}

pub fn with_bytes_reader<t>(bytes: &[u8], f: fn(Reader) -> t) -> t {
pub pure fn with_bytes_reader<t>(bytes: &[u8], f: fn(Reader) -> t) -> t {
f({buf: bytes, mut pos: 0u} as Reader)
}

Expand Down Expand Up @@ -730,21 +730,25 @@ impl @BytesWriter : Writer {
fn get_type() -> WriterType { (*self).get_type() }
}
pub fn BytesWriter() -> BytesWriter {
pub pure fn BytesWriter() -> BytesWriter {
BytesWriter { buf: DVec(), mut pos: 0u }
}
pub fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
pub pure fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
let wr = @BytesWriter();
f(wr as Writer);
wr.buf.check_out(|buf| move buf)
// FIXME (#3758): This should not be needed.
unsafe { wr.buf.check_out(|buf| move buf) }
}
pub fn with_str_writer(f: fn(Writer)) -> ~str {
pub pure fn with_str_writer(f: fn(Writer)) -> ~str {
let mut v = with_bytes_writer(f);
// Make sure the vector has a trailing null and is proper utf8.
v.push(0);
// FIXME (#3758): This should not be needed.
unsafe {
// Make sure the vector has a trailing null and is proper utf8.
v.push(0);
}
assert str::is_utf8(v);
unsafe { move ::cast::transmute(move v) }
Expand Down

0 comments on commit b18a151

Please sign in to comment.