refactor keymap map visitor to reduce # of cases

pull/3958/head
Matthew Cheely 2 years ago
parent be13c26c80
commit 73d8700f60

@ -218,20 +218,16 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor {
match command { match command {
None => Ok(KeyTrie::Node(KeyTrieNode::new(label, mapping, order))), None => Ok(KeyTrie::Node(KeyTrieNode::new(label, mapping, order))),
Some(cmd) => { Some(cmd) => {
if label.is_empty() { let status = (cmd, label.is_empty());
Ok(KeyTrie::Leaf(cmd)) if let (MappableCommand::Typable { name, args, .. }, false) = status {
Ok(MappableCommand::Typable {
name,
args,
doc: label.to_string(),
})
.map(KeyTrie::Leaf)
} else { } else {
match cmd { Ok(KeyTrie::Leaf(status.0))
MappableCommand::Typable { name, args, .. } => {
Ok(MappableCommand::Typable {
name,
args,
doc: label.to_string(),
})
.map(KeyTrie::Leaf)
}
MappableCommand::Static { .. } => Ok(KeyTrie::Leaf(cmd)),
}
} }
} }
} }

Loading…
Cancel
Save