aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: d7dadad5e7eb2dccd01d5b1dd120d2d02087cdab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
mod table;
mod definitions;

pub use definitions::{Action, State, unpack};

use table::{EXIT_ACTIONS, ENTRY_ACTIONS, STATE_CHANGE};

impl State {
    /// Get exit action for this state
    #[inline(always)]
    pub fn exit_action(&self) -> Action {
        unsafe {
            ::table::EXIT_ACTIONS.get_unchecked(*self as usize)
        }
    }

    /// Get entry action for this state
    #[inline(always)]
    pub fn entry_action(&self) -> Action {
        unsafe {
            ::table::ENTRY_ACTIONS.get_unchecked(*self as usize)
        }
    }
}


// struct StateMachine<P: Parser> {
//     state: State,
// }
// 
// trait Parser {
//     fn csi_entry(&mut self, c: char);
//     fn csi_param(&mut self, c: char);
// }
// 
// struct Foo;
// 
// impl Parser for Foo {
//     fn csi_entry(&mut self, c: char) {
//         println!("csi_entry char={:?}", c);
//     }
//     fn csi_param(&mut self, c: char) {
//         println!("csi_param char={:?}", c);
//     }
// }
// 
// #[test]
// fn it_works() {
//     let table: u8 = &[Parser::csi_entry, Parser::csi_param];
//     let mut foo = Foo;
//     table[0](&mut foo, 'b');
// }