Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. trait MyTrait {
  2. fn foo();
  3. }
  4.  
  5. struct DefaultImpl;
  6. impl MyTrait for DefaultImpl {
  7. fn foo() {
  8. println!("foo default");
  9. }
  10. }
  11.  
  12. struct TestImpl;
  13. impl MyTrait for TestImpl {
  14. fn foo() {
  15. println!("foo test");
  16. }
  17. }
  18.  
  19. fn print_foo<T>()
  20. where
  21. T: MyTrait,
  22. {
  23. T::foo();
  24. }
  25.  
  26. fn main() {
  27. print_foo::<DefaultImpl>();
  28. print_foo::<TestImpl>();
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement