Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. trait HasDefault {
  2.  
  3. fn default() -> Self;
  4.  
  5. }
  6.  
  7. struct DefaultOne;
  8.  
  9. impl Default for DefaultOne {
  10. fn default() -> Self {
  11. DefaultOne{}
  12. }
  13. }
  14.  
  15. struct DefaultTwo;
  16. impl Default for DefaultTwo {
  17. fn default() -> Self {
  18. DefaultTwo{}
  19. }
  20. }
  21.  
  22. pub fn main() {
  23. println!("Hello");
  24. let v = vec![DefaultOne::default, DefaultTwo::default];
  25. let w = vec![DefaultOne::default(), DefaultTwo::default()];
  26.  
  27. // Iterate over v or w using just methods in the Default trait
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement