mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-06-01 02:08:06 +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();
|
||
|
}
|
||
|
|