From cebdd3be32d50be379663e92d4428e6bba19ba51 Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Sun, 2 Apr 2023 21:59:22 +0200 Subject: Run cargo fmt I think readability was better before that... --- examples/text-adventure/side_effects.rs | 42 +++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'examples/text-adventure/side_effects.rs') 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 +} -- cgit v1.2.3