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