Created
January 31, 2021 04:35
-
-
Save grahamking/03c8549fce6115631e5ce439c4488be2 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
trait Logger { | |
fn log(&self, s: &str); | |
fn err(&self, e: &str); | |
} | |
struct StdoutLogger {} | |
impl Logger for StdoutLogger { | |
fn log(&self, s: &str) { | |
println!("{}", s); | |
} | |
fn err(&self, e: &str) { | |
self.log(e); | |
} | |
} | |
fn run(l: &dyn Logger) { | |
l.log("Hello"); | |
l.err("Oops"); | |
} | |
fn main() { | |
let l = StdoutLogger {}; | |
run(&l); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment