Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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