X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/e73ddf5e1d4768cb86fba3eb583f4fec0286acff..8fcdbed310c53f621fba0401399659ed1a1ec446:/src/part10.rs diff --git a/src/part10.rs b/src/part10.rs index 97dd4c1..53fb0b3 100644 --- a/src/part10.rs +++ b/src/part10.rs @@ -28,19 +28,14 @@ impl Action for PrintWithString { } } -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 +fn print_with_prefix_v1(b: &BigInt, prefix: String) { + let my_action = PrintWithString { prefix: prefix }; + b.act_v1(my_action); } -pub fn main_v1() { - let prefix = read_one_line(); - let my_action = PrintWithString { prefix: prefix }; +pub fn main() { let bignum = BigInt::new(1 << 63) + BigInt::new(1 << 16) + BigInt::new(1 << 63); - bignum.act_v1(my_action); + print_with_prefix_v1(&bignum, "Digit: ".to_string()); } impl BigInt { @@ -51,10 +46,8 @@ impl BigInt { } } -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) ); +pub fn print_with_prefix(b: &BigInt, prefix: String) { + b.act(|digit| println!("{}{}", prefix, digit) ); } //@ [index](main.html) | [previous](part08.html) | [next](main.html)