From 7e8ee5ed9cad6484e9f13f81731b102ced58402e Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Tue, 9 Jul 2019 15:14:04 -0400 Subject: Init. --- meap/meap-code/ch3/ch3-skeleton-read-trait.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 meap/meap-code/ch3/ch3-skeleton-read-trait.rs (limited to 'meap/meap-code/ch3/ch3-skeleton-read-trait.rs') diff --git a/meap/meap-code/ch3/ch3-skeleton-read-trait.rs b/meap/meap-code/ch3/ch3-skeleton-read-trait.rs new file mode 100755 index 0000000..9189bef --- /dev/null +++ b/meap/meap-code/ch3/ch3-skeleton-read-trait.rs @@ -0,0 +1,21 @@ +#![allow(unused_variables)] + +#[derive(Debug)] +struct File; + +trait Read { + fn read(self: &Self, save_to: &mut Vec) -> Result; +} + +impl Read for File { + fn read(self: &File, save_to: &mut Vec) -> Result { + 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); +} \ No newline at end of file -- cgit v1.2.3