X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/9f6c55ebcab2e1d3073e8bb6c8c910d0116efee4..ab7f9b241429bd675b437d2437799de75d2f409b:/workspace/src/part10.rs?ds=inline diff --git a/workspace/src/part10.rs b/workspace/src/part10.rs deleted file mode 100644 index 570e851..0000000 --- a/workspace/src/part10.rs +++ /dev/null @@ -1,52 +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 print_with_prefix_v1(b: &BigInt, prefix: String) { - let my_action = PrintWithString { prefix: prefix }; - b.act_v1(my_action); -} - -pub fn main() { - let bignum = BigInt::new(1 << 63) + BigInt::new(1 << 16) + BigInt::new(1 << 63); - print_with_prefix_v1(&bignum, "Digit: ".to_string()); -} - -impl BigInt { - fn act(&self, mut a: A) { - for digit in self { - a(digit); - } - } -} - -pub fn print_with_prefix(b: &BigInt, prefix: String) { - b.act(|digit| println!("{}{}", prefix, digit) ); -} -