summaryrefslogblamecommitdiff
path: root/meap/meap-code/ch3/ch3-skeleton-read-trait.rs
blob: 9189bef2f7d012ccef536c56d9f9665f7b426eb7 (plain) (tree)




















                                                                           
#![allow(unused_variables)]

#[derive(Debug)]
struct File;

trait Read {          
    fn read(self: &Self, save_to: &mut Vec<u8>) -> Result<usize, String>;
}

impl Read for File {
    fn read(self: &File, save_to: &mut Vec<u8>) -> Result<usize, String> {
        Ok(0)
    }
}

fn main() {
    let f = File{};
    let mut buffer = vec!();
    let n_bytes = f.read(&mut buffer).unwrap();
    println!("{} byte(s) read from {:?}", n_bytes, f);
}