Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. pub trait Hash {
  2. fn hash(&self) -> usize;
  3. }
  4. impl Hash for usize {
  5. fn hash(&self) -> usize {
  6. *self % 10
  7. }
  8. }
  9. impl Hash for String {
  10. fn hash(&self) -> usize {
  11. self.len() % 24
  12. }
  13. }
  14.  
  15. fn foo(x: impl Hash) {
  16. println!("hash is {}", x.hash());
  17. }
  18.  
  19. fn main() {
  20. foo(32usize);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement