Guest User

Untitled

a guest
May 28th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. trait Foo {
  2. fn foo(&self) -> u32;
  3. }
  4.  
  5. impl<T: AsRef<[u32]>> Foo for T {
  6. fn foo(&self) -> u32 {
  7. self.as_ref()[0]
  8. }
  9. }
  10.  
  11. fn bar<T>(f: T) -> u32
  12. where
  13. T: Foo,
  14. {
  15. f.foo() + 1
  16. }
  17.  
  18. fn main() {
  19. let f: &[u32] = &[42];
  20. bar(f);
  21. let v = vec![34, 12];
  22. bar(&v);
  23. }
Add Comment
Please, Sign In to add comment