Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- // Set float and int, m and b, respectively.
- let (fm, fb) = (3.0, 2.0);
- let (im, ib) = (3, 2);
- // Two closures each using floats and ints
- let float_line = move |x| fm * x + fb;
- let int_line = |x| im * x + ib;
- // Interesting bit. The slope_function doesn't set
- // type inference to float, once the 'I' type is used.
- let i_line = slope_function(int_line, 2);
- let f_line = slope_function(float_line, 2.0);
- println!("Hello, world! {:?} {:?} {:?}", float_line(2.0), i_line, f_line);
- }
- // Closure function taking a closure, and int as input.
- fn slope_function<I>(f: impl Fn(I) -> I, x: I) -> I {
- f(x)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement