<commit_before>#[macro_use]
extern crate log;

#[macro_use]
mod macros;

#[cfg(test)]
mod tests;

#[derive(Debug)]
enum Event<UsrEvt> {
    Enter,
    User(UsrEvt),
    Exit
}

enum Action<'a, UsrEvt> {
    Ignore,
    Transition(&'a State<'a, UsrEvt>)
}
impl<'a, UsrEvt> ::std::fmt::Display for Action<'a, UsrEvt> {
    fn fmt(&self, f:&mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
        match *self {
            Action::Ignore         => ::std::fmt::Display::fmt("Ignore", f),
            Action::Transition(..) => ::std::fmt::Display::fmt("Transition", f),
        };
        Ok(())
    }
}

trait State<'a, UsrEvt> {
    fn handle_event(&'a mut self, evt: Event<UsrEvt>) -> Action<'a, UsrEvt>;
}

trait StateLookup<StEnum, UsrEvt> {
    fn lookup(&mut self, typ: &StEnum) -> &mut State<UsrEvt>;
}

trait Initializer {
    fn new() -> Self;
}


struct StateMachine<UsrEvt, UsrStEnum, UsrSt> {
    current  : UsrStEnum,
    states   : UsrSt,
    _phantom : ::std::marker::PhantomData<UsrEvt>
}
impl<UsrEvt, UsrStEnum, UsrSt> StateMachine<UsrEvt, UsrStEnum, UsrSt>
    where UsrSt: Initializer + StateLookup<UsrStEnum, UsrEvt>,
          UsrEvt: ::std::fmt::Debug {
    fn new(initial: UsrStEnum) -> Self {
        StateMachine {
            current  : initial,
            states   : UsrSt::new(),
            _phantom : ::std::marker::PhantomData
        }
    }

    fn input(&mut self, evt: Event<UsrEvt>) {
        info!("input: {:?}", evt);
    }
}<commit_msg>more logging<commit_after>#[macro_use]
extern crate log;

#[macro_use]
mod macros;

#[cfg(test)]
mod tests;


macro_rules! paste_action_fmt_fn {
    () => {
        fn fmt(&self, f:&mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
            match *self {
                Action::Ignore         => ::std::fmt::Display::fmt("Ignore", f),
                Action::Transition(..) => ::std::fmt::Display::fmt("Transition", f),
            };
            Ok(())
        }
    }
}
enum Action<'a, UsrEvt> {
    Ignore,
    Transition(&'a State<'a, UsrEvt>)
}
impl<'a, UsrEvt> ::std::fmt::Display for Action<'a, UsrEvt> {
    paste_action_fmt_fn!();
}
impl<'a, UsrEvt> ::std::fmt::Debug for Action<'a, UsrEvt> {
    paste_action_fmt_fn!();
}


#[derive(Debug)]
enum Event<UsrEvt> {
    Enter,
    User(UsrEvt),
    Exit
}

trait State<'a, UsrEvt> {
    fn handle_event(&'a mut self, evt: Event<UsrEvt>) -> Action<'a, UsrEvt>;
}

trait StateLookup<StEnum, UsrEvt> {
    fn lookup(&mut self, typ: &StEnum) -> &mut State<UsrEvt>;
}

trait Initializer {
    fn new() -> Self;
}


struct StateMachine<UsrEvt, UsrStEnum, UsrSt> {
    current  : UsrStEnum,
    states   : UsrSt,
    _phantom : ::std::marker::PhantomData<UsrEvt>
}
impl<UsrEvt, UsrStEnum, UsrSt> StateMachine<UsrEvt, UsrStEnum, UsrSt>
    where UsrSt     : Initializer + StateLookup<UsrStEnum, UsrEvt>,
          UsrEvt    : ::std::fmt::Debug,
          UsrStEnum : ::std::fmt::Debug  {
    fn new(initial: UsrStEnum) -> Self {
        StateMachine {
            current  : initial,
            states   : UsrSt::new(),
            _phantom : ::std::marker::PhantomData
        }
    }

    fn input(&mut self, evt: Event<UsrEvt>) {
        info!("input:  {:?}", evt);
        info!("state:  {:?}", self.current);
        let cur_st = self.states.lookup(&self.current);
        let action = cur_st.handle_event(evt);
        info!("action: {:?}", action)

    }
}
{'fraction_non_alphanumeric': 0.17979502196193264, 'fraction_numerical': 0.0, 'mean_word_length': 2.851183765501691, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7001293', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1296, 'n_words': 245}