Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum Anything
- {
- Something,
- Nothing,
- }
- type Search = fn(&Life) -> Status;
- enum Status
- {
- Searching(Search),
- Answer(Anything),
- }
- struct Life;
- impl Life
- {
- fn understanding(&self) -> Status
- {
- // This is a simulation
- // Status::Answer(Anything::Nothing)
- // Status::Answer(Anything::Something)
- Status::Searching(Life::enlightenment)
- }
- fn enlightenment(&self) -> Status
- {
- Status::Answer(Anything::Nothing)
- }
- }
- fn search_origin(life: &Life) -> Status
- {
- life.understanding()
- }
- fn main()
- {
- let life = Life;
- let mut most_important_thing_in_life: Status;
- most_important_thing_in_life = Status::Searching(search_origin);
- while let Status::Searching(search) = most_important_thing_in_life
- {
- println!("{:?}", most_important_thing_in_life);
- most_important_thing_in_life = search(&life);
- }
- println!("{:?}", most_important_thing_in_life);
- }
- use std::fmt::{
- self,
- Debug,
- Formatter,
- };
- impl Debug for Anything
- {
- fn fmt(&self, formatter: &mut Formatter) -> fmt::Result
- {
- use Anything::*;
- match self
- {
- Something => write!(formatter, "Something"),
- Nothing => write!(formatter, "Nothing"),
- }
- }
- }
- impl Debug for Status
- {
- fn fmt(&self, formatter: &mut Formatter) -> fmt::Result
- {
- use Status::*;
- match self
- {
- Searching(_) => write!(formatter, "Searching"),
- Answer(answer) => write!(formatter, "Answer({:?})", answer),
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement