aboutsummaryrefslogtreecommitdiff
path: root/codegen/src
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-09-16 20:24:37 -0700
committerJoe Wilm <joe@jwilm.com>2016-09-16 20:24:37 -0700
commit0e9785ccc1d2c440d4251df74c909964fd46f312 (patch)
tree4416e471e5ab6b1c49272d90c76a4715b90b0720 /codegen/src
parent5fdda06c3b48d7a5976a0e865f689247bc4fc855 (diff)
downloadr-alacritty-vte-0e9785ccc1d2c440d4251df74c909964fd46f312.tar.gz
r-alacritty-vte-0e9785ccc1d2c440d4251df74c909964fd46f312.tar.bz2
r-alacritty-vte-0e9785ccc1d2c440d4251df74c909964fd46f312.zip
Add custom Debug for ext::Transition
This shows the variant in addition to the packed value - much more helpful when debugging.
Diffstat (limited to 'codegen/src')
-rw-r--r--codegen/src/ext.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/codegen/src/ext.rs b/codegen/src/ext.rs
index 0124435..94fdd51 100644
--- a/codegen/src/ext.rs
+++ b/codegen/src/ext.rs
@@ -1,3 +1,5 @@
+use std::fmt;
+
use syntex::Registry;
use syntex_syntax::ast::{self, ExprKind, MetaItem, Arm, Expr, PatKind, LitKind, Pat};
@@ -141,21 +143,35 @@ fn input_mapping_from_arm(arm: Arm, cx: &mut ExtCtxt) -> Result<InputMapping, ()
}
/// What happens when certain input is received
-#[derive(Debug)]
+#[derive(Copy, Clone)]
enum Transition {
State(State),
Action(Action),
StateAction(State, Action),
}
+impl fmt::Debug for Transition {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ Transition::State(state) => try!(write!(f, "State({:?})", state)),
+ Transition::Action(action) => try!(write!(f, "Action({:?})", action)),
+ Transition::StateAction(state, action) => {
+ try!(write!(f, "StateAction({:?}, {:?})", state, action));
+ }
+ }
+
+ write!(f, " -> {:?}", self.pack_u8())
+ }
+}
+
impl Transition {
// State is stored in the top 4 bits
fn pack_u8(&self) -> u8 {
match *self {
- Transition::State(ref state) => (*state as u8) << 4,
- Transition::Action(ref action) => *action as u8,
- Transition::StateAction(ref state, ref action) => {
- ((*state as u8) << 4) & (*action as u8)
+ Transition::State(state) => state as u8,
+ Transition::Action(action) => (action as u8) << 4,
+ Transition::StateAction(state, action) => {
+ ((action as u8) << 4) | (state as u8)
}
}
}