Fix clippy warnings.
This commit is contained in:
parent
51dd9c4fa1
commit
049ebbefdb
|
@ -1,2 +1,3 @@
|
|||
max_width = 120
|
||||
use_small_heuristics = "Max"
|
||||
use_field_init_shorthand = true
|
||||
|
|
|
@ -22,7 +22,7 @@ pub struct Bits {
|
|||
impl Bits {
|
||||
/// Constructs a new, empty bits structure.
|
||||
pub fn new(version: Version) -> Self {
|
||||
Self { data: Vec::new(), bit_offset: 0, version: version }
|
||||
Self { data: Vec::new(), bit_offset: 0, version }
|
||||
}
|
||||
|
||||
/// Pushes an N-bit big-endian integer to the end of the bits.
|
||||
|
@ -255,7 +255,7 @@ impl Bits {
|
|||
self.push_number(2, 0b10);
|
||||
self.push_number(14, eci_designator.as_u16());
|
||||
}
|
||||
16384...999999 => {
|
||||
16384...999_999 => {
|
||||
self.push_number(3, 0b110);
|
||||
self.push_number(5, (eci_designator >> 16).as_u16());
|
||||
self.push_number(16, (eci_designator & 0xffff).as_u16());
|
||||
|
@ -688,7 +688,7 @@ impl Bits {
|
|||
}
|
||||
|
||||
if self.len() < data_length {
|
||||
const PADDING_BYTES: &'static [u8] = &[0b11101100, 0b00010001];
|
||||
const PADDING_BYTES: &[u8] = &[0b1110_1100, 0b0001_0001];
|
||||
|
||||
self.bit_offset = 0;
|
||||
let data_bytes_length = data_length / 8;
|
||||
|
|
|
@ -93,12 +93,7 @@ impl Canvas {
|
|||
/// Constructs a new canvas big enough for a QR code of the given version.
|
||||
pub fn new(version: Version, ec_level: EcLevel) -> Self {
|
||||
let width = version.width();
|
||||
Self {
|
||||
width: width,
|
||||
version: version,
|
||||
ec_level: ec_level,
|
||||
modules: vec![Module::Empty; (width * width).as_usize()],
|
||||
}
|
||||
Self { width, version, ec_level, modules: vec![Module::Empty; (width * width).as_usize()] }
|
||||
}
|
||||
|
||||
/// Converts the canvas into a human-readable string.
|
||||
|
@ -1149,7 +1144,7 @@ impl DataModuleIter {
|
|||
Self {
|
||||
x: width - 1,
|
||||
y: width - 1,
|
||||
width: width,
|
||||
width,
|
||||
timing_pattern_column: match version {
|
||||
Version::Micro(_) => 0,
|
||||
Version::Normal(_) => 6,
|
||||
|
|
19
src/lib.rs
19
src/lib.rs
|
@ -31,12 +31,16 @@
|
|||
|
||||
#![cfg_attr(feature = "bench", feature(test, external_doc))] // Unstable libraries
|
||||
#![cfg_attr(feature = "cargo-clippy", deny(warnings, clippy_pedantic))]
|
||||
#![cfg_attr(feature = "cargo-clippy",
|
||||
allow(unreadable_literal, missing_docs_in_private_items, shadow_reuse,
|
||||
range_plus_one))]
|
||||
|
||||
#![cfg_attr(
|
||||
feature = "cargo-clippy",
|
||||
allow(
|
||||
indexing_slicing,
|
||||
write_literal, // see https://github.com/rust-lang-nursery/rust-clippy/issues/2976
|
||||
)
|
||||
)]
|
||||
#![cfg_attr(feature = "bench", doc(include = "../README.md"))]
|
||||
// ^ make sure we can test our README.md.
|
||||
#![cfg_attr(feature = "cargo-clippy", allow())]
|
||||
|
||||
extern crate checked_int_cast;
|
||||
#[cfg(feature = "image")]
|
||||
|
@ -147,12 +151,7 @@ impl QrCode {
|
|||
canvas.draw_all_functional_patterns();
|
||||
canvas.draw_data(&*encoded_data, &*ec_data);
|
||||
let canvas = canvas.apply_best_mask();
|
||||
Ok(Self {
|
||||
content: canvas.into_colors(),
|
||||
version: version,
|
||||
ec_level: ec_level,
|
||||
width: version.width().as_usize(),
|
||||
})
|
||||
Ok(Self { content: canvas.into_colors(), version, ec_level, width: version.width().as_usize() })
|
||||
}
|
||||
|
||||
/// Gets the version of this QR code.
|
||||
|
|
|
@ -271,14 +271,14 @@ impl<I: Iterator<Item = Segment>> Optimizer<I> {
|
|||
parser: segments,
|
||||
last_segment: Segment { mode: Mode::Numeric, begin: 0, end: 0 },
|
||||
last_segment_size: 0,
|
||||
version: version,
|
||||
version,
|
||||
ended: true,
|
||||
},
|
||||
Some(segment) => Self {
|
||||
parser: segments,
|
||||
last_segment: segment,
|
||||
last_segment_size: segment.encoded_len(version),
|
||||
version: version,
|
||||
version,
|
||||
ended: false,
|
||||
},
|
||||
}
|
||||
|
|
34
src/types.rs
34
src/types.rs
|
@ -129,8 +129,8 @@ pub enum Version {
|
|||
impl Version {
|
||||
/// Get the number of "modules" on each size of the QR code, i.e. the width
|
||||
/// and height of the code.
|
||||
pub fn width(&self) -> i16 {
|
||||
match *self {
|
||||
pub fn width(self) -> i16 {
|
||||
match self {
|
||||
Version::Normal(v) => v * 4 + 17,
|
||||
Version::Micro(v) => v * 2 + 9,
|
||||
}
|
||||
|
@ -146,11 +146,11 @@ impl Version {
|
|||
///
|
||||
/// If the entry compares equal to the default value of T, this method
|
||||
/// returns `Err(QrError::InvalidVersion)`.
|
||||
pub fn fetch<T>(&self, ec_level: EcLevel, table: &[[T; 4]]) -> QrResult<T>
|
||||
pub fn fetch<T>(self, ec_level: EcLevel, table: &[[T; 4]]) -> QrResult<T>
|
||||
where
|
||||
T: PartialEq + Default + Copy,
|
||||
{
|
||||
match *self {
|
||||
match self {
|
||||
Version::Normal(v @ 1...40) => {
|
||||
return Ok(table[(v - 1).as_usize()][ec_level as usize]);
|
||||
}
|
||||
|
@ -166,16 +166,16 @@ impl Version {
|
|||
}
|
||||
|
||||
/// The number of bits needed to encode the mode indicator.
|
||||
pub fn mode_bits_count(&self) -> usize {
|
||||
match *self {
|
||||
pub fn mode_bits_count(self) -> usize {
|
||||
match self {
|
||||
Version::Micro(a) => (a - 1).as_usize(),
|
||||
_ => 4,
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks whether is version refers to a Micro QR code.
|
||||
pub fn is_micro(&self) -> bool {
|
||||
match *self {
|
||||
pub fn is_micro(self) -> bool {
|
||||
match self {
|
||||
Version::Normal(_) => false,
|
||||
Version::Micro(_) => true,
|
||||
}
|
||||
|
@ -212,28 +212,28 @@ impl Mode {
|
|||
///
|
||||
/// This method will return `Err(QrError::UnsupportedCharacterSet)` if the
|
||||
/// mode is not supported in the given version.
|
||||
pub fn length_bits_count(&self, version: Version) -> usize {
|
||||
pub fn length_bits_count(self, version: Version) -> usize {
|
||||
match version {
|
||||
Version::Micro(a) => {
|
||||
let a = a.as_usize();
|
||||
match *self {
|
||||
match self {
|
||||
Mode::Numeric => 2 + a,
|
||||
Mode::Alphanumeric | Mode::Byte => 1 + a,
|
||||
Mode::Kanji => a,
|
||||
}
|
||||
}
|
||||
Version::Normal(1...9) => match *self {
|
||||
Version::Normal(1...9) => match self {
|
||||
Mode::Numeric => 10,
|
||||
Mode::Alphanumeric => 9,
|
||||
Mode::Byte | Mode::Kanji => 8,
|
||||
},
|
||||
Version::Normal(10...26) => match *self {
|
||||
Version::Normal(10...26) => match self {
|
||||
Mode::Numeric => 12,
|
||||
Mode::Alphanumeric => 11,
|
||||
Mode::Byte => 16,
|
||||
Mode::Kanji => 10,
|
||||
},
|
||||
Version::Normal(_) => match *self {
|
||||
Version::Normal(_) => match self {
|
||||
Mode::Numeric => 14,
|
||||
Mode::Alphanumeric => 13,
|
||||
Mode::Byte => 16,
|
||||
|
@ -250,8 +250,8 @@ impl Mode {
|
|||
///
|
||||
/// Note that in Kanji mode, the `raw_data_len` is the number of Kanjis,
|
||||
/// i.e. half the total size of bytes.
|
||||
pub fn data_bits_count(&self, raw_data_len: usize) -> usize {
|
||||
match *self {
|
||||
pub fn data_bits_count(self, raw_data_len: usize) -> usize {
|
||||
match self {
|
||||
Mode::Numeric => (raw_data_len * 10 + 2) / 3,
|
||||
Mode::Alphanumeric => (raw_data_len * 11 + 1) / 2,
|
||||
Mode::Byte => raw_data_len * 8,
|
||||
|
@ -269,10 +269,10 @@ impl Mode {
|
|||
/// assert!(a <= c);
|
||||
/// assert!(b <= c);
|
||||
///
|
||||
pub fn max(&self, other: Self) -> Self {
|
||||
pub fn max(self, other: Self) -> Self {
|
||||
match self.partial_cmp(&other) {
|
||||
Some(Ordering::Less) | Some(Ordering::Equal) => other,
|
||||
Some(Ordering::Greater) => *self,
|
||||
Some(Ordering::Greater) => self,
|
||||
None => Mode::Byte,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue