Simplified Rust code to avoid fully qualifying enum constants in exhaustive matches.

pull/31/head
Project Nayuki 7 years ago
parent b0f4c1450c
commit d1989e912b

@ -725,22 +725,24 @@ impl QrCodeEcc {
// Returns an unsigned 2-bit integer (in the range 0 to 3). // Returns an unsigned 2-bit integer (in the range 0 to 3).
fn ordinal(&self) -> usize { fn ordinal(&self) -> usize {
use QrCodeEcc::*;
match *self { match *self {
QrCodeEcc::Low => 0, Low => 0,
QrCodeEcc::Medium => 1, Medium => 1,
QrCodeEcc::Quartile => 2, Quartile => 2,
QrCodeEcc::High => 3, High => 3,
} }
} }
// Returns an unsigned 2-bit integer (in the range 0 to 3). // Returns an unsigned 2-bit integer (in the range 0 to 3).
fn format_bits(&self) -> u32 { fn format_bits(&self) -> u32 {
use QrCodeEcc::*;
match *self { match *self {
QrCodeEcc::Low => 1, Low => 1,
QrCodeEcc::Medium => 0, Medium => 0,
QrCodeEcc::Quartile => 3, Quartile => 3,
QrCodeEcc::High => 2, High => 2,
} }
} }
@ -1030,12 +1032,13 @@ impl QrSegmentMode {
// Returns an unsigned 4-bit integer value (range 0 to 15) // Returns an unsigned 4-bit integer value (range 0 to 15)
// representing the mode indicator bits for this mode object. // representing the mode indicator bits for this mode object.
fn mode_bits(&self) -> u32 { fn mode_bits(&self) -> u32 {
use QrSegmentMode::*;
match *self { match *self {
QrSegmentMode::Numeric => 0x1, Numeric => 0x1,
QrSegmentMode::Alphanumeric => 0x2, Alphanumeric => 0x2,
QrSegmentMode::Byte => 0x4, Byte => 0x4,
QrSegmentMode::Kanji => 0x8, Kanji => 0x8,
QrSegmentMode::Eci => 0x7, Eci => 0x7,
} }
} }
@ -1043,12 +1046,13 @@ impl QrSegmentMode {
// Returns the bit width of the segment character count field // Returns the bit width of the segment character count field
// for this mode object at the given version number. // for this mode object at the given version number.
pub fn num_char_count_bits(&self, ver: Version) -> u8 { pub fn num_char_count_bits(&self, ver: Version) -> u8 {
use QrSegmentMode::*;
let array: [u8; 3] = match *self { let array: [u8; 3] = match *self {
QrSegmentMode::Numeric => [10, 12, 14], Numeric => [10, 12, 14],
QrSegmentMode::Alphanumeric => [ 9, 11, 13], Alphanumeric => [ 9, 11, 13],
QrSegmentMode::Byte => [ 8, 16, 16], Byte => [ 8, 16, 16],
QrSegmentMode::Kanji => [ 8, 10, 12], Kanji => [ 8, 10, 12],
QrSegmentMode::Eci => [ 0, 0, 0], Eci => [ 0, 0, 0],
}; };
let ver = ver.value(); let ver = ver.value();

Loading…
Cancel
Save