libstd: Remove mutable fields from flatpipes and io_util

This commit is contained in:
Patrick Walton 2013-05-02 22:44:03 -07:00
parent da2ac90812
commit 92d2ec4d32
2 changed files with 15 additions and 13 deletions

View File

@ -558,9 +558,11 @@ pub mod bytepipes {
} }
} }
// XXX: Remove `@mut` when this module is ported to the new I/O traits,
// which use `&mut self` properly.
pub struct PipeBytePort { pub struct PipeBytePort {
port: comm::Port<~[u8]>, port: comm::Port<~[u8]>,
mut buf: ~[u8] buf: @mut ~[u8]
} }
pub struct PipeByteChan { pub struct PipeByteChan {
@ -569,13 +571,13 @@ pub mod bytepipes {
impl BytePort for PipeBytePort { impl BytePort for PipeBytePort {
fn try_recv(&self, count: uint) -> Option<~[u8]> { fn try_recv(&self, count: uint) -> Option<~[u8]> {
if vec::uniq_len(&const self.buf) >= count { if vec::uniq_len(&const *self.buf) >= count {
let mut bytes = ::core::util::replace(&mut self.buf, ~[]); let mut bytes = ::core::util::replace(&mut *self.buf, ~[]);
self.buf = bytes.slice(count, bytes.len()).to_owned(); *self.buf = bytes.slice(count, bytes.len()).to_owned();
bytes.truncate(count); bytes.truncate(count);
return Some(bytes); return Some(bytes);
} else if vec::uniq_len(&const self.buf) > 0 { } else if vec::uniq_len(&const *self.buf) > 0 {
let mut bytes = ::core::util::replace(&mut self.buf, ~[]); let mut bytes = ::core::util::replace(&mut *self.buf, ~[]);
assert!(count > bytes.len()); assert!(count > bytes.len());
match self.try_recv(count - bytes.len()) { match self.try_recv(count - bytes.len()) {
Some(rest) => { Some(rest) => {
@ -584,11 +586,11 @@ pub mod bytepipes {
} }
None => return None None => return None
} }
} else if vec::uniq_len(&const self.buf) == 0 { } else if vec::uniq_len(&const *self.buf) == 0 {
match self.port.try_recv() { match self.port.try_recv() {
Some(buf) => { Some(buf) => {
assert!(!buf.is_empty()); assert!(!buf.is_empty());
self.buf = buf; *self.buf = buf;
return self.try_recv(count); return self.try_recv(count);
} }
None => return None None => return None
@ -609,7 +611,7 @@ pub mod bytepipes {
fn new(p: Port<~[u8]>) -> PipeBytePort { fn new(p: Port<~[u8]>) -> PipeBytePort {
PipeBytePort { PipeBytePort {
port: p, port: p,
buf: ~[] buf: @mut ~[]
} }
} }
} }

View File

@ -13,14 +13,14 @@ use core::io;
pub struct BufReader { pub struct BufReader {
buf: ~[u8], buf: ~[u8],
mut pos: uint pos: @mut uint
} }
pub impl BufReader { pub impl BufReader {
pub fn new(v: ~[u8]) -> BufReader { pub fn new(v: ~[u8]) -> BufReader {
BufReader { BufReader {
buf: v, buf: v,
pos: 0 pos: @mut 0
} }
} }
@ -29,13 +29,13 @@ pub impl BufReader {
// I can't get the borrowing to work correctly // I can't get the borrowing to work correctly
let bytes_reader = BytesReader { let bytes_reader = BytesReader {
bytes: ::core::util::id::<&[u8]>(self.buf), bytes: ::core::util::id::<&[u8]>(self.buf),
pos: self.pos pos: *self.pos
}; };
let res = f(&bytes_reader); let res = f(&bytes_reader);
// FIXME #4429: This isn't correct if f fails // FIXME #4429: This isn't correct if f fails
self.pos = bytes_reader.pos; *self.pos = bytes_reader.pos;
return res; return res;
} }