2019-07-27 00:54:25 +03:00
|
|
|
// run-pass
|
|
|
|
|
2014-07-23 19:57:30 -07:00
|
|
|
use std::ops::FnMut;
|
|
|
|
|
2015-01-12 10:27:25 -05:00
|
|
|
fn call_f<F:FnMut()>(mut f: F) {
|
2014-07-23 19:57:30 -07:00
|
|
|
f();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn f() {
|
|
|
|
println!("hello");
|
|
|
|
}
|
|
|
|
|
2015-01-12 10:27:25 -05:00
|
|
|
fn call_g<G:FnMut(String,String) -> String>(mut g: G, x: String, y: String)
|
2014-07-23 19:57:30 -07:00
|
|
|
-> String {
|
|
|
|
g(x, y)
|
|
|
|
}
|
|
|
|
|
2014-10-14 23:05:01 -07:00
|
|
|
fn g(mut x: String, y: String) -> String {
|
2015-02-01 21:53:25 -05:00
|
|
|
x.push_str(&y);
|
2014-10-14 23:05:01 -07:00
|
|
|
x
|
2014-07-23 19:57:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
call_f(f);
|
2015-02-01 21:53:25 -05:00
|
|
|
assert_eq!(call_g(g, "foo".to_string(), "bar".to_string()),
|
2014-07-23 19:57:30 -07:00
|
|
|
"foobar");
|
|
|
|
}
|