summary refs log blame commit diff stats
path: root/src/error.rs
blob: 032e2c20ea493ef9bbb9694ade0afd48adf3ce2d (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                                           


















                                                  
pub fn helper<T, V>(res: Result<T, V>) -> T
where
    V: std::fmt::Debug,
{
    match res {
        Ok(val) => val,
        Err(err) => {
            log::error!("{:?}", err);
            panic!("{:?}", err);
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn shouldnt_panic() {
        let ok: Result<&str, &str> = Ok("okay");
        let rhs = helper(ok);
        assert_eq!("okay", rhs);
    }

    #[test]
    #[should_panic]
    fn should_panic() {
        let err: Result<&str, &str> = Err("oops");
        helper(err);
    }
}
ard)) ((s string-address))) ((s 1)) nil cn0: checking arg ((s string-address)) maybe-add: ((s string-address)) cn0: checking oarg ((x keyboard-address)) maybe-add: ((x keyboard-address)) cn0: location for oarg ((x keyboard-address)): 2 cn0: (((1 character-address) (raw)) <- ((read-key)) ((x keyboard-address))) ((s 1) (x 2)) nil cn0: checking arg ((x keyboard-address)) maybe-add: ((x keyboard-address)) cn0: checking oarg ((1 character-address) (raw)) maybe-add: ((1 character-address) (raw)) cn0: (((1 character-address) (raw)) <- ((read-key)) ((x keyboard-address))) ((s 1) (x 2)) nil cn0: checking arg ((x keyboard-address)) maybe-add: ((x keyboard-address)) cn0: checking oarg ((1 character-address) (raw)) maybe-add: ((1 character-address) (raw)) cn1: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal))) cn1: (((1 string-address)) <- ((new)) foo) cn1: (((2 keyboard-address)) <- ((init-keyboard)) ((1 string-address))) cn1: (((1 character-address) (raw)) <- ((read-key)) ((2 keyboard-address))) cn1: (((1 character-address) (raw)) <- ((read-key)) ((2 keyboard-address))) schedule: main run: main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal))) run: main 0: 1000 => ((default-space space-address)) run: main 1: (((1 string-address)) <- ((new)) foo) run: main 1: 1031 => ((1 string-address)) mem: ((1 string-address)): 1002 <= 1031 run: main 2: (((2 keyboard-address)) <- ((init-keyboard)) ((1 string-address))) mem: ((1 string-address)) => 1031 run: init-keyboard/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal))) run: init-keyboard/main 0: 1035 => ((default-space space-address)) run: init-keyboard/main 1: (((1 keyboard-address)) <- ((new)) ((keyboard literal))) run: init-keyboard/main 1: 1066 => ((1 keyboard-address)) mem: ((1 keyboard-address)): 1037 <= 1066 run: init-keyboard/main 2: (((2 string-address-address)) <- ((get-address)) ((1 keyboard-address) (deref)) ((1 offset))) run: init-keyboard/main 2: 1067 => ((2 string-address-address)) mem: ((2 string-address-address)): 1038 <= 1067 run: init-keyboard/main 3: (((2 string-address-address) (deref)) <- ((next-input))) arg: nil 0 (1031) run: init-keyboard/main 3: 1031 => ((2 string-address-address) (deref)) mem: ((2 string-address-address) (deref)): 1067 <= 1031 run: init-keyboard/main 4: (((3 integer-address)) <- ((get-address)) ((1 keyboard-address) (deref)) ((0 offset))) run: init-keyboard/main 4: 1066 => ((3 integer-address)) mem: ((3 integer-address)): 1039 <= 1066 run: init-keyboard/main 5: (((3 integer-address) (deref)) <- ((copy)) ((0 literal))) run: init-keyboard/main 5: 0 => ((3 integer-address) (deref)) mem: ((3 integer-address) (deref)): 1066 <= 0 run: init-keyboard/main 6: (((reply)) ((1 keyboard-address))) mem: ((1 keyboard-address)) => 1066 run: main 2: 1066 => ((2 keyboard-address)) mem: ((2 keyboard-address)): 1003 <= 1066 run: main 3: (((1 character-address) (raw)) <- ((read-key)) ((2 keyboard-address))) mem: ((2 keyboard-address)) => 1066 run: read-key/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal))) run: read-key/main 0: 1068 => ((default-space space-address)) run: read-key/main 1: (((1 keyboard-address)) <- ((next-input))) arg: nil 0 (1066) run: read-key/main 1: 1066 => ((1 keyboard-address)) mem: ((1 keyboard-address)): 1070 <= 1066 run: read-key/main 2: (((2 terminal-address)) <- ((next-input))) arg: nil 1 (1066) run: read-key/main 2: nil => ((2 terminal-address)) mem: ((2 terminal-address)): 1071 <= nil run: read-key/main 3: (((jump-unless)) ((1 keyboard-address)) ((9 offset))) mem: ((1 keyboard-address)) => 1066 run: read-key/main 4: (((3 integer-address)) <- ((get-address)) ((1 keyboard-address) (deref)) ((0 offset))) run: read-key/main 4: 1066 => ((3 integer-address)) mem: ((3 integer-address)): 1072 <= 1066 run: read-key/main 5: (((4 string-address)) <- ((get)) ((1 keyboard-address) (deref)) ((1 offset))) mem: ((1067 string-address) (raw)) => 1031 run: read-key/main 5: 1031 => ((4 string-address)) mem: ((4 string-address)): 1073 <= 1031 run: read-key/main 6: (((5 integer)) <- ((length)) ((4 string-address) (deref))) array-len: ((4 string-address) (deref)) mem: ((1031 integer) (raw)) => 3 run: read-key/main 6: 3 => ((5 integer)) mem: ((5 integer)): 1074 <= 3 run: read-key/main 7: (((6 boolean)) <- ((greater-or-equal)) ((3 integer-address) (deref)) ((5 integer))) mem: ((3 integer-address) (deref)) => 0 mem: ((5 integer)) => 3 run: read-key/main 7: nil => ((6 boolean)) mem: ((6 boolean)): 1075 <= nil run: read-key/main 8: (((jump-unless)) ((6 boolean)) ((1 offset))) mem: ((6 boolean)) => nil run: read-key/main 10: (((7 character)) <- ((index)) ((4 string-address) (deref)) ((3 integer-address) (deref))) mem: ((3 integer-address) (deref)) => 0 array-len: ((1031 string) (raw)) mem: ((1031 integer) (raw)) => 3 mem: ((1032 byte) (raw)) => f run: read-key/main 10: #\f => ((7 character)) mem: ((7 character)): 1076 <= #\f run: read-key/main 11: (((3 integer-address) (deref)) <- ((add)) ((3 integer-address) (deref)) ((1 literal))) mem: ((3 integer-address) (deref)) => 0 run: read-key/main 11: 1 => ((3 integer-address) (deref)) mem: ((3 integer-address) (deref)): 1066 <= 1 run: read-key/main 12: (((reply)) ((7 character))) mem: ((7 character)) => f run: main 3: #\f => ((1 character-address) (raw)) mem: ((1 character-address) (raw)): 1 <= #\f run: main 4: (((1 character-address) (raw)) <- ((read-key)) ((2 keyboard-address))) mem: ((2 keyboard-address)) => 1066 run: read-key/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal))) run: read-key/main 0: 1099 => ((default-space space-address)) run: read-key/main 1: (((1 keyboard-address)) <- ((next-input))) arg: nil 0 (1066) run: read-key/main 1: 1066 => ((1 keyboard-address)) mem: ((1 keyboard-address)): 1101 <= 1066 run: read-key/main 2: (((2 terminal-address)) <- ((next-input))) arg: nil 1 (1066) run: read-key/main 2: nil => ((2 terminal-address)) mem: ((2 terminal-address)): 1102 <= nil run: read-key/main 3: (((jump-unless)) ((1 keyboard-address)) ((9 offset))) mem: ((1 keyboard-address)) => 1066 run: read-key/main 4: (((3 integer-address)) <- ((get-address)) ((1 keyboard-address) (deref)) ((0 offset))) run: read-key/main 4: 1066 => ((3 integer-address)) mem: ((3 integer-address)): 1103 <= 1066 run: read-key/main 5: (((4 string-address)) <- ((get)) ((1 keyboard-address) (deref)) ((1 offset))) mem: ((1067 string-address) (raw)) => 1031 run: read-key/main 5: 1031 => ((4 string-address)) mem: ((4 string-address)): 1104 <= 1031 run: read-key/main 6: (((5 integer)) <- ((length)) ((4 string-address) (deref))) array-len: ((4 string-address) (deref)) mem: ((1031 integer) (raw)) => 3 run: read-key/main 6: 3 => ((5 integer)) mem: ((5 integer)): 1105 <= 3 run: read-key/main 7: (((6 boolean)) <- ((greater-or-equal)) ((3 integer-address) (deref)) ((5 integer))) mem: ((3 integer-address) (deref)) => 1 mem: ((5 integer)) => 3 run: read-key/main 7: nil => ((6 boolean)) mem: ((6 boolean)): 1106 <= nil run: read-key/main 8: (((jump-unless)) ((6 boolean)) ((1 offset))) mem: ((6 boolean)) => nil run: read-key/main 10: (((7 character)) <- ((index)) ((4 string-address) (deref)) ((3 integer-address) (deref))) mem: ((3 integer-address) (deref)) => 1 array-len: ((1031 string) (raw)) mem: ((1031 integer) (raw)) => 3 mem: ((1033 byte) (raw)) => o run: read-key/main 10: #\o => ((7 character)) mem: ((7 character)): 1107 <= #\o run: read-key/main 11: (((3 integer-address) (deref)) <- ((add)) ((3 integer-address) (deref)) ((1 literal))) mem: ((3 integer-address) (deref)) => 1 run: read-key/main 11: 2 => ((3 integer-address) (deref)) mem: ((3 integer-address) (deref)): 1066 <= 2 run: read-key/main 12: (((reply)) ((7 character))) mem: ((7 character)) => o run: main 4: #\o => ((1 character-address) (raw)) mem: ((1 character-address) (raw)): 1 <= #\o schedule: done with routine nil