728x90
fn fn_closure<F>(f: F)
where
F: Fn()
{
f();
}
fn fn_mut_closure<F>(mut f: F)
where
F: FnMut(),
{
f();
}
fn fn_once_closure<F>(f: F)
where
F: FnOnce(),
{
f();
}
fn main() {
let mut my_string = String::from("Hello there");
/*
let print_it = || {
drop(my_string);
};
print_if();
*/
fn_once_closure(|| {
my_string.push('a);
println!("{my_string}");
drop(my_string);
})
}
728x90
'Rust' 카테고리의 다른 글
[Rust lang] 92. attribute part (0) | 2023.03.30 |
---|---|
[Rust lang] 91. about impl trait (0) | 2023.03.30 |
[Rust lang] 89. function pointers (0) | 2023.03.30 |
[Rust lang] 88. three types of generics (0) | 2023.03.30 |
[Rust lang] 87. trait objects, box (0) | 2023.03.30 |
댓글