Guest User

Untitled

a guest
Jul 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. pub trait State {}
  2. pub struct Fun;
  3. impl State for Fun {}
  4. pub struct Sad;
  5. impl State for Sad {}
  6.  
  7. pub struct J<T: State> {
  8. s: T
  9. }
  10.  
  11. impl J<Sad> {
  12. fn new() -> J<Sad> {
  13. J{s: Sad}
  14. }
  15. }
  16.  
  17. impl <T: State> J<T> {
  18. fn change<TT: State>(self, t: TT) -> J<TT> {
  19. J { s: t}
  20. }
  21. }
  22.  
  23. pub trait Funny {
  24. fn fun(&mut self);
  25. }
  26.  
  27. pub struct JuJu<T: State> { /// don't want to have type parameter here
  28. j: J<T>
  29. }
  30.  
  31. impl <T: State> Funny for JuJu<T> {
  32. fn fun(&mut self) {
  33. self.j = self.j.change(Fun)
  34. }
  35. }
  36.  
  37. fn main() {
  38. println!("Hello, world!");
  39. }
Add Comment
Please, Sign In to add comment