let mut key: u64 = 0;
let mut shift = 0;
while let Some(&ch) = self.next() {
match ch {
b'a'..=b'z' if shift < 64 => {
key |= (ch as u64) << shift;
shift += 8;
}
b' ' | b'\t' | b'\r' | b'\n' => (),
b'=' => {
return key.into();
}
b'A'..=b'Z' if shift < 64 => {
key |= ((ch - b'A' + b'a') as u64) << shift;
shift += 8;
}
b';' => {
key = 0;
}
_ => {
key = u64::MAX;
shift = 64;
}
}
}
pub(crate) const A: u64 = b'a' as u64;
pub(crate) const B: u64 = b'b' as u64;
pub(crate) const BH: u64 = (b'b' as u64) | ((b'h' as u64) << 8);
match key {
A => {
// do something for A
}
B => {
// do something for B
}
BH => {
// do something for BH
}
_ => {}
}
原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。