Closed
Description
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.
fn read(&self, bytes: &[mut u8], len: uint) -> uint;
}
pub trait ReaderUtil {
/// Read len bytes into a new vec.
fn read_bytes(&self, len: uint) -> ~[u8];
}
impl<T: Reader> T : ReaderUtil {
fn read_bytes(&self, len: uint) -> ~[u8] {
let mut bytes = vec::with_capacity(len);
unsafe { vec::raw::set_len(&mut bytes, len); }
let count = (&*self).read(bytes, len);
unsafe { vec::raw::set_len(&mut bytes, count); }
move bytes
}
}
impl int: Reader {
fn read(&self, bytes: &[mut u8], len: uint) -> uint {
0
}
}
fn main() {
let x = @0;
let x = x as @Reader;
x.read_bytes(0);
}
rustc: /home/brian/dev/rust/src/llvm/include/llvm/Instructions.h:705: llvm::Type* llvm::checkGEPType(llvm::Type*): Assertion `Ty && "Invalid GetElementPtrInst indices for type!"' failed.