struct S { v: i64 } fn sum(n_orig: std::rc::Rc) -> impl Fn(i64) -> i64 { let n = n_orig.clone(); let res = move |x| { x + n.v }; println!("N is {}", n_orig.v); res } fn main() { let n = 1; let f = sum(std::rc::Rc::new(S{v:n})); let v = 5; println!("Add {} {} = {}", v, n, f(v)) }