Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. use std::clone::Clone;
  2. use std::fmt::Display;
  3.  
  4. trait Cloneable: Clone + Display {}
  5.  
  6. impl Cloneable for u32 {}
  7.  
  8. struct ThingA<CloneableThisIsAGenericTypeParameterDeclaration> {
  9. val: CloneableThisIsAGenericTypeParameterDeclaration,
  10. }
  11.  
  12. impl<CloneableThisIsAnotherGenericTypeParameterDeclaration: Cloneable> ThingA<CloneableThisIsAnotherGenericTypeParameterDeclaration> {
  13. pub fn new(val: CloneableThisIsAnotherGenericTypeParameterDeclaration) -> Self {
  14. Self {
  15. val,
  16. }
  17. }
  18.  
  19. pub fn print(&self) {
  20. let c = self.val.clone();
  21. println!("{}", c);
  22. }
  23. }
  24.  
  25. fn main() {
  26. println!("Hello, world!");
  27. let thing_a = ThingA::<u32>::new(42);
  28. thing_a.print();
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement