1 // Rust-101, Part 09: Closures (WIP)
2 // =================================
4 use std::io::prelude::*;
10 fn do_action(&mut self, digit: u64);
14 fn act_v1<A: Action>(&self, mut a: A) {
21 struct PrintWithString {
25 impl Action for PrintWithString {
26 fn do_action(&mut self, digit: u64) {
27 println!("{}{}", self.prefix, digit);
31 fn print_with_prefix_v1(b: &BigInt, prefix: String) {
32 let my_action = PrintWithString { prefix: prefix };
37 let bignum = BigInt::new(1 << 63) + BigInt::new(1 << 16) + BigInt::new(1 << 63);
38 print_with_prefix_v1(&bignum, "Digit: ".to_string());
42 fn act<A: FnMut(u64)>(&self, mut a: A) {
49 pub fn print_with_prefix(b: &BigInt, prefix: String) {
50 b.act(|digit| println!("{}{}", prefix, digit) );