mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-14 17:42:41 +00:00
27 lines
468 B
Rust
27 lines
468 B
Rust
// ./src/fn/closures/input_functions.md
|
|
|
|
|
|
// Define a function which takes a generic `F` argument
|
|
// bounded by `Fn`, and calls it
|
|
fn call_me<F: Fn()>(f: F) {
|
|
f();
|
|
}
|
|
|
|
// Define a wrapper function satisfying the `Fn` bound
|
|
fn function() {
|
|
println!("I'm a function!");
|
|
}
|
|
|
|
fn part0() {
|
|
// Define a closure satisfying the `Fn` bound
|
|
let closure = || println!("I'm a closure!");
|
|
|
|
call_me(closure);
|
|
call_me(function);
|
|
}
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|