Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. enum Anything
  2. {
  3. Something,
  4. Nothing,
  5. }
  6.  
  7. type Search = fn(&Life) -> Status;
  8.  
  9. enum Status
  10. {
  11. Searching(Search),
  12. Answer(Anything),
  13. }
  14.  
  15. struct Life;
  16.  
  17. impl Life
  18. {
  19. fn understanding(&self) -> Status
  20. {
  21. // This is a simulation
  22. Status::Answer(Anything::Nothing)
  23. }
  24. }
  25.  
  26. fn search_origin(life: &Life) -> Status
  27. {
  28. life.understanding()
  29. }
  30.  
  31. fn main()
  32. {
  33. let life = Life;
  34. let mut most_important_thing_in_life: Status;
  35.  
  36. most_important_thing_in_life = Status::Searching(search_origin);
  37.  
  38. while let Status::Searching(search) = most_important_thing_in_life
  39. {
  40. most_important_thing_in_life = search(&life);
  41. }
  42.  
  43. println!("{:?}", most_important_thing_in_life);
  44. }
  45.  
  46. use std::fmt::{
  47. self,
  48. Debug,
  49. Formatter,
  50. };
  51.  
  52. impl Debug for Anything
  53. {
  54. fn fmt(&self, formatter: &mut Formatter) -> fmt::Result
  55. {
  56. use Anything::*;
  57.  
  58. match self
  59. {
  60. Something => write!(formatter, "Something"),
  61. Nothing => write!(formatter, "Nothing"),
  62. }
  63. }
  64. }
  65.  
  66. impl Debug for Status
  67. {
  68. fn fmt(&self, formatter: &mut Formatter) -> fmt::Result
  69. {
  70. use Status::*;
  71.  
  72. match self
  73. {
  74. Searching(_) => write!(formatter, "Searching"),
  75. Answer(answer) => write!(formatter, "Answer({:?})", answer),
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement