From b18a15171bfbcde81c44967a865214389d6fd7ad Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 18 Oct 2012 09:04:47 -0700 Subject: [PATCH] Make with_bytes_reader/with_bytes_writer pure --- src/libcore/dvec.rs | 2 +- src/libcore/io.rs | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 1540eb30fe5a4..1b6a7522864ef 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -56,7 +56,7 @@ pub enum DVec { } /// Creates a new, empty dvec -pub fn DVec() -> DVec { +pub pure fn DVec() -> DVec { DVec_({mut data: ~[]}) } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index fd0fcbbe1c1f8..41fc1bb1a69ec 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -328,7 +328,7 @@ impl ByteBuf: Reader { fn tell() -> uint { self.pos } } -pub fn with_bytes_reader(bytes: &[u8], f: fn(Reader) -> t) -> t { +pub pure fn with_bytes_reader(bytes: &[u8], f: fn(Reader) -> t) -> t { f({buf: bytes, mut pos: 0u} as Reader) } @@ -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) }