Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring ReaderUtil trait, combining it with the traitless impl on Reader #3589

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ trait Reader {
trait ReaderUtil {
fn read_bytes(len: uint) -> ~[u8];
fn read_line() -> ~str;

fn read_chars(n: uint) -> ~[char];
fn read_char() -> char;
fn read_c_str() -> ~str;
fn read_le_uint(size: uint) -> uint;
fn read_le_int(size: uint) -> int;
fn read_be_uint(size: uint) -> uint;
fn read_whole_stream() -> ~[u8];
fn each_byte(it: fn(int) -> bool);
fn each_char(it: fn(char) -> bool);
fn each_line(it: fn(~str) -> bool);
}

impl<T: Reader> T : ReaderUtil {
Expand All @@ -69,12 +80,12 @@ impl<T: Reader> T : ReaderUtil {
}
str::from_bytes(buf)
}
}

impl Reader {
fn read_chars(n: uint) -> ~[char] {
// returns the (consumed offset, n_req), appends characters to &chars
fn chars_from_bytes(buf: ~[u8], &chars: ~[char]) -> (uint, uint) {
fn chars_from_bytes<T: Reader>(buf: ~[u8], &chars: ~[char])
-> (uint, uint)
{
let mut i = 0u;
while i < vec::len(buf) {
let b0 = buf[i];
Expand Down Expand Up @@ -118,7 +129,7 @@ impl Reader {
break;
}
vec::push_all(buf, data);
let (offset, nbreq) = chars_from_bytes(buf, chars);
let (offset, nbreq) = chars_from_bytes::<T>(buf, chars);
let ncreq = n - vec::len(chars);
// again we either know we need a certain number of bytes
// to complete a character, or we make sure we don't
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use core::cmp::{Eq, Ord};
use result::{Result, Ok, Err};
use io::WriterUtil;
use io::{WriterUtil, ReaderUtil};
use map::HashMap;
use map::Map;
use sort::Sort;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use core::cmp::Eq;
use libc::{c_char, c_int, c_long, size_t, time_t};
use io::Reader;
use io::{Reader, ReaderUtil};
use result::{Result, Ok, Err};

export
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/parse/comments.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use io::println;//XXXXXXXXxxx
use io::ReaderUtil;
use util::interner;
use lexer::{string_reader, bump, is_eof, nextch,
is_whitespace, get_str_from, reader};
Expand Down
1 change: 1 addition & 0 deletions src/rustc/driver/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use core::*;

// -*- rust -*-
use result::{Ok, Err};
use io::ReaderUtil;
use std::getopts;
use std::map::HashMap;
use getopts::{opt_present};
Expand Down