Guest User

Untitled

a guest
Jun 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. use std::mem;
  2.  
  3. trait Alteration {
  4. fn method(&self);
  5. }
  6.  
  7. enum State {
  8. Foo {
  9. var: Box<Alteration>
  10. },
  11. Bar {
  12. var: Box<Alteration>
  13. },
  14. Invalid,
  15. }
  16.  
  17. struct Uploader {
  18. state: State
  19. }
  20.  
  21. impl Uploader {
  22. fn problem(&mut self) {
  23. let old_state = mem::replace(&mut self.state, State::Invalid);
  24. let next_state = match old_state {
  25. State::Foo { var } => State::Bar { var },
  26. _ => return,
  27. };
  28. self.state = next_state;
  29. if let State::Invalid = self.state {
  30. panic!();
  31. }
  32. }
  33.  
  34. }
  35.  
  36. fn main() {
  37.  
  38. }
Add Comment
Please, Sign In to add comment