FnOnce/call_once question

#![feature(fn_traits)]

fn main() {
    let s = "hello".to_string();
    let mut c = ||{println!("{:?}", s)};
    c();
    c.call_mut(());
    c.call_once(());
    c();    //why "c" is valid after call_once,call_once will move "self"
}

Closures implement Copy when possible, and yours only captures a reference to s, so it's perfectly copyable.

8 Likes