// x is borrowed here fn fn1 ( x: &i32 ) -> i32 { return 3*x*x + 4*x + 3i32; } fn fn2 ( _x: &i32 ) -> i32 { return 1; } // takes an x and a function, which takes an integer and returns an integer fn call_fn ( x: &i32, fct: &dyn Fn(&i32)->i32 ) -> i32 { return fct(x); } fn main() { let vals = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]; // {} inserts a value, :>width$ inside specifies how this value is presented, // -> its aligned to the right (>), the parameter "width" specifies how many spaces are emitted. println!("{:>width$} | {:>width$} | {:>width$}", "x", "fn1(x)", "fn2(x)", width=10); println!("-----------+------------+-----------"); // using a borrowed vals here also makes x borrowed. for x in &vals { println!("{:>width$} | {:>width$} | {:>width$}", x, call_fn( x, &fn1 ), call_fn( x, &fn2 ), width=10) } }