1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 /* Any copyright is dedicated to the Public Domain.
12 * http://creativecommons.org/publicdomain/zero/1.0/ */
14 #![feature(unboxed_closures)]
17 use std::io::stdio::println;
20 where F : FnOnce(String) -> String
22 println!("{}", f("Fred".to_string()))
25 fn call_a_thunk<F>(f: F) where F: FnOnce() {
29 fn call_this<F>(f: F) where F: FnOnce(&str) + Send {
33 fn call_bare(f: fn(&str)) {
37 fn call_bare_again(f: extern "Rust" fn(&str)) {
44 let greeting = "Hello ".to_string();
46 format!("{}{}", greeting, s)
49 let greeting = "Goodbye ".to_string();
50 call_it(|s| format!("{}{}", greeting, s));
52 let greeting = "How's life, ".to_string();
53 call_it(|s: String| -> String {
54 format!("{}{}", greeting, s)
59 call_a_thunk(|| println!("Hello world!"));
61 call_this(|s| println!("{}", s));
67 call_bare_again(println);