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 read_one_line() -> String {
32 println!("Please enter a line of text.");
33 let mut stdin = io::stdin();
34 let mut prefix = "".to_string();
35 stdin.read_line(&mut prefix).unwrap();
40 let prefix = read_one_line();
41 let my_action = PrintWithString { prefix: prefix };
42 let bignum = BigInt::new(1 << 63) + BigInt::new(1 << 16) + BigInt::new(1 << 63);
43 bignum.act_v1(my_action);
47 fn act<A: FnMut(u64)>(&self, mut a: A) {
55 let prefix = read_one_line();
56 let bignum = BigInt::new(1 << 63) + BigInt::new(1 << 16) + BigInt::new(1 << 63);
57 bignum.act(|digit| println!("{}{}", prefix, digit) );
60 //@ [index](main.html) | [previous](part08.html) | [next](main.html)