Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code shared from the Rust Playground
use std::borrow::Borrow;
struct Bar {
greetings:String
}
trait Foo {
fn hi(&self);
}
// impl<'a> Foo for &'a Bar {
// fn hi(&self) {
// print!("hi")
// }
// }
// impl Foo for Bar {
// fn hi(&self) {
// print!("hi")
// }
// }
impl<B: Borrow<Bar>> Foo for B {
fn hi(&self) {
print!("hi {}",self.greetings)
}
}
fn test<F:Foo>(s:F){
s.hi()
}
fn main() {
let bar = Bar {
greetings:",there!".to_string(),
};
test(&bar);
test(bar);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.