Created
May 23, 2017 07:34
-
-
Save mclosson/c41371fd04f4b6ac5e02f9ca99d79076 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
fn output<F: Fn(String)>(text: &str, strategy: F) { | |
let string = String::from(text); | |
strategy(string) | |
} | |
// define strategies as closures | |
let bold = |s| println!("<strong>{}</strong>", s); | |
let italics = |s| println!("<em>{}</em>", s); | |
let header = |s| println!("<h1>{}</h1>", s); | |
let text = "This is a test."; | |
// call output using each strategy | |
output(text, bold); | |
output(text, italics); | |
output(text, header); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment