Skip to content

Commit 135ebca

Browse files
eholkbrson
authored andcommitted
Refactoring ReaderUtil trait, combining it with the traitless impl on Reader.
1 parent f41cf20 commit 135ebca

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

src/libcore/io.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ trait Reader {
4848
trait ReaderUtil {
4949
fn read_bytes(len: uint) -> ~[u8];
5050
fn read_line() -> ~str;
51+
52+
fn read_chars(n: uint) -> ~[char];
53+
fn read_char() -> char;
54+
fn read_c_str() -> ~str;
55+
fn read_le_uint(size: uint) -> uint;
56+
fn read_le_int(size: uint) -> int;
57+
fn read_be_uint(size: uint) -> uint;
58+
fn read_whole_stream() -> ~[u8];
59+
fn each_byte(it: fn(int) -> bool);
60+
fn each_char(it: fn(char) -> bool);
61+
fn each_line(it: fn((&str)) -> bool);
5162
}
5263

5364
impl<T: Reader> T : ReaderUtil {
@@ -69,12 +80,10 @@ impl<T: Reader> T : ReaderUtil {
6980
}
7081
str::from_bytes(buf)
7182
}
72-
}
7383

74-
impl Reader {
7584
fn read_chars(n: uint) -> ~[char] {
7685
// returns the (consumed offset, n_req), appends characters to &chars
77-
fn chars_from_bytes(buf: &~[u8], chars: &mut ~[char])
86+
fn chars_from_bytes<T: Reader>(buf: &~[u8], chars: &mut ~[char])
7887
-> (uint, uint) {
7988
let mut i = 0;
8089
let buf_len = buf.len();
@@ -120,7 +129,7 @@ impl Reader {
120129
break;
121130
}
122131
vec::push_all(buf, data);
123-
let (offset, nbreq) = chars_from_bytes(&buf, &mut chars);
132+
let (offset, nbreq) = chars_from_bytes::<T>(&buf, &mut chars);
124133
let ncreq = n - chars.len();
125134
// again we either know we need a certain number of bytes
126135
// to complete a character, or we make sure we don't

src/libstd/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
use core::cmp::{Eq, Ord};
1010
use result::{Result, Ok, Err};
11-
use io::WriterUtil;
11+
use io::{WriterUtil, ReaderUtil};
1212
use map::HashMap;
1313
use map::Map;
1414
use sort::Sort;

src/libstd/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use core::cmp::Eq;
55
use libc::{c_char, c_int, c_long, size_t, time_t};
6-
use io::Reader;
6+
use io::{Reader, ReaderUtil};
77
use result::{Result, Ok, Err};
88

99
export

src/libsyntax/parse/comments.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use io::println;//XXXXXXXXxxx
2+
use io::ReaderUtil;
23
use util::interner;
34
use lexer::{string_reader, bump, is_eof, nextch,
45
is_whitespace, get_str_from, reader};

src/rustc/driver/rustc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use core::*;
1212

1313
// -*- rust -*-
1414
use result::{Ok, Err};
15+
use io::ReaderUtil;
1516
use std::getopts;
1617
use std::map::HashMap;
1718
use getopts::{opt_present};

0 commit comments

Comments
 (0)