2012-12-13 15:09:38 -06:00
|
|
|
pub trait Reader {
|
|
|
|
// FIXME (#2004): Seekable really should be orthogonal.
|
|
|
|
|
|
|
|
/// Read up to len bytes (or EOF) and put them into bytes (which
|
|
|
|
/// must be at least len bytes long). Return number of bytes read.
|
|
|
|
// FIXME (#2982): This should probably return an error.
|
2013-01-29 20:30:22 -06:00
|
|
|
fn read(&self, bytes: &mut [u8], len: uint) -> uint;
|
2012-12-13 15:09:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait ReaderUtil {
|
|
|
|
|
|
|
|
/// Read len bytes into a new vec.
|
|
|
|
fn read_bytes(len: uint);
|
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl<T: Reader> ReaderUtil for T {
|
2012-12-13 15:09:38 -06:00
|
|
|
|
|
|
|
fn read_bytes(len: uint) {
|
2013-01-30 21:36:51 -06:00
|
|
|
let mut count = self.read(&mut [0], len);
|
2012-12-13 15:09:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
x: int,
|
|
|
|
y: int
|
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl Reader for S {
|
2013-01-29 20:30:22 -06:00
|
|
|
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
|
2012-12-13 15:09:38 -06:00
|
|
|
0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2012-12-13 15:09:38 -06:00
|
|
|
let x = S { x: 1, y: 2 };
|
|
|
|
let x = x as @Reader;
|
|
|
|
x.read_bytes(0);
|
|
|
|
}
|