X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/e73ddf5e1d4768cb86fba3eb583f4fec0286acff..ab7f9b241429bd675b437d2437799de75d2f409b:/workspace/src/part10.rs diff --git a/workspace/src/part10.rs b/workspace/src/part10.rs deleted file mode 100644 index ee226c4..0000000 --- a/workspace/src/part10.rs +++ /dev/null @@ -1,59 +0,0 @@ -// Rust-101, Part 09: Closures (WIP) -// ================================= - -use std::io::prelude::*; -use std::io; - -use part05::BigInt; - -trait Action { - fn do_action(&mut self, digit: u64); -} - -impl BigInt { - fn act_v1(&self, mut a: A) { - for digit in self { - a.do_action(digit); - } - } -} - -struct PrintWithString { - prefix: String, -} - -impl Action for PrintWithString { - fn do_action(&mut self, digit: u64) { - println!("{}{}", self.prefix, digit); - } -} - -fn read_one_line() -> String { - println!("Please enter a line of text."); - let mut stdin = io::stdin(); - let mut prefix = "".to_string(); - stdin.read_line(&mut prefix).unwrap(); - prefix -} - -pub fn main_v1() { - let prefix = read_one_line(); - let my_action = PrintWithString { prefix: prefix }; - let bignum = BigInt::new(1 << 63) + BigInt::new(1 << 16) + BigInt::new(1 << 63); - bignum.act_v1(my_action); -} - -impl BigInt { - fn act(&self, mut a: A) { - for digit in self { - a(digit); - } - } -} - -pub fn main() { - let prefix = read_one_line(); - let bignum = BigInt::new(1 << 63) + BigInt::new(1 << 16) + BigInt::new(1 << 63); - bignum.act(|digit| println!("{}{}", prefix, digit) ); -} -