Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait T {
- fn f(&self);
- }
- #[allow(dead_code)]
- struct A {
- i: i32
- }
- impl T for A {
- fn f(&self) {}
- }
- fn f<T : ?Sized>(_: &T) {}
- //fn g<T : ?Sized>(_: T) {} Error
- trait T2 {
- fn foo(&self) -> Box<T2>;
- fn bar() -> Box<T2> where Self : Sized;
- }
- impl T2 for A {
- fn foo(&self) -> Box<T2> {
- println!("foo");
- Box::new(A{ i: 5 })
- }
- fn bar() -> Box<T2> {
- println!("bar");
- Box::new(A{ i: 5 })
- }
- }
- trait T3 {} // : Sized {}
- impl T3 for A {}
- fn main() {
- let a = A{ i: 5 };
- let _t : &T = &a;
- f::<T>(&a);
- let _b : Box<T2> = T2::foo(&a);
- let _c : Box<T2> = <A as T2>::bar();
- let _d : &T3 = &A{i: 5};
- }
Add Comment
Please, Sign In to add comment