Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. struct Sessionv1 {
  2. pub some_field: bool,
  3. pub some_field2: bool
  4. }
  5.  
  6. enum Session<T: SessionTrait> {
  7. V1(Sessionv1),
  8. Whatever(T),
  9. }
  10.  
  11. impl<NotFinSession> Session<NotFinSession>
  12. where NotFinSession: SessionTrait {
  13. pub fn set_some_field(&self, _val: bool) {
  14.  
  15. }
  16.  
  17. pub fn finalize(self) -> Result<Session::<FinSession>, ()> {
  18. match self {
  19. Session::V1(v) => Ok(Session::<FinSession>::V1(v)),
  20. _ => Err(()),
  21. }
  22.  
  23. }
  24. }
  25.  
  26. impl<FinSession> Session<FinSession>
  27. where FinSession: SessionTrait {
  28. pub fn set_some_field2(&self, _val: bool) {
  29.  
  30. }
  31. }
  32.  
  33. impl<FinSession> Session<FinSession>
  34. where FinSession: SessionTrait {
  35. }
  36.  
  37. trait SessionTrait {
  38. }
  39.  
  40. struct FinSession {
  41. }
  42.  
  43. impl SessionTrait for FinSession {
  44. }
  45.  
  46. struct NotFinSession {
  47. }
  48.  
  49. impl SessionTrait for NotFinSession {
  50. }
  51.  
  52. pub fn main() {
  53. let session = Session::<NotFinSession>::V1(Sessionv1{some_field: false, some_field2: false});
  54. session.set_some_field(false);
  55. let fin_session: Session<FinSession> = session.finalize().unwrap();
  56. fin_session.set_some_field2(true);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement