diff options
| author | Andreas Grois <andi@grois.info> | 2023-04-02 21:59:22 +0200 |
|---|---|---|
| committer | Andreas Grois <andi@grois.info> | 2023-04-02 21:59:22 +0200 |
| commit | cebdd3be32d50be379663e92d4428e6bba19ba51 (patch) | |
| tree | 8c5b57f2e2ed3c089e0546fdb95ef8c2082d1952 /examples/text-adventure/side_effects.rs | |
| parent | 418f514fc46f45ae2901753e3398adb33664bed9 (diff) | |
Run cargo fmt
I think readability was better before that...
Diffstat (limited to 'examples/text-adventure/side_effects.rs')
| -rw-r--r-- | examples/text-adventure/side_effects.rs | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/examples/text-adventure/side_effects.rs b/examples/text-adventure/side_effects.rs index dd911dd..379ed5d 100644 --- a/examples/text-adventure/side_effects.rs +++ b/examples/text-adventure/side_effects.rs @@ -2,22 +2,30 @@ use crate::dsl::FreeSausageRoll; -pub fn run<'a, 's:'a>(mut game : FreeSausageRoll<'a, 's, ()>) -> std::io::Result<()>{ +pub fn run<'a, 's: 'a>(mut game: FreeSausageRoll<'a, 's, ()>) -> std::io::Result<()> { //this function doesn't know who it is, or why it is here. It only knows it must deal. //Deal with the few commands in the eDSL and nothing more. //This would be easier to write recursively. However, in an actual project this might run for quite some time. //Since we operate on the stack, let's rather be safe than sorry, and use a loop instead of recursion therefore. - while let FreeSausageRoll::Free(command) = game { + while let FreeSausageRoll::Free(command) = game { game = match *command { - crate::dsl::SausageRoll::SayDialogueLine { speaker, text, mood, next } => { - println!("{} says: \"{text}\" with {} on their face.", speaker.text_description(), mood.text_description()); + crate::dsl::SausageRoll::SayDialogueLine { + speaker, + text, + mood, + next, + } => { + println!( + "{} says: \"{text}\" with {} on their face.", + speaker.text_description(), + mood.text_description() + ); next - }, - crate::dsl::SausageRoll::GivePlayerOptions { options, next } => - { + } + crate::dsl::SausageRoll::GivePlayerOptions { options, next } => { println!("Your options are:"); - for (id, option) in options.iter().enumerate().map(|(i,o)| (i+1,o)){ + for (id, option) in options.iter().enumerate().map(|(i, o)| (i + 1, o)) { println!("{id}: {option}"); } @@ -26,23 +34,27 @@ pub fn run<'a, 's:'a>(mut game : FreeSausageRoll<'a, 's, ()>) -> std::io::Result while { input.clear(); std::io::stdin().read_line(&mut input)?; - chosen = input.trim().parse().ok().filter(|o : &usize| *o > 0 && *o <= options.len()); + chosen = input + .trim() + .parse() + .ok() + .filter(|o: &usize| *o > 0 && *o <= options.len()); chosen.is_none() } { println!("Invalid choice. Please select one of the options given above."); } println!(); - next(chosen.unwrap()-1) - }, + next(chosen.unwrap() - 1) + } crate::dsl::SausageRoll::PresentLocation { location, next } => { println!("{}", location.get_text_description()); next - }, + } crate::dsl::SausageRoll::Exposition { text, next } => { println!("{text}"); next - }, + } }; - }; + } std::io::Result::Ok(()) -}
\ No newline at end of file +} |
