Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Foo {
- fn fn1(&self) -> i32;
- }
- struct FooImpl;
- impl Foo for FooImpl {
- fn fn1(&self) -> i32 { 1 }
- }
- trait FooExt : Foo {
- fn fn_ext(&self) -> i32 {
- self.fn1() + 1
- }
- }
- impl<T: Foo> FooExt for T {}
- impl<'a> Foo for &'a Foo {
- fn fn1(&self) -> i32 {
- (*self).fn1()
- }
- }
- fn func(f: &Foo) {
- println!("func fn1: {}", f.fn1());
- println!("func fn_ext: {}", f.fn_ext());
- }
- fn main() {
- let f = FooImpl;
- println!("fn1: {}", f.fn1());
- println!("fn_ext: {}", f.fn_ext());
- func(&f);
- }
Add Comment
Please, Sign In to add comment