From 068707d3124decf7d4fb7384f9e358ff526ce6d1 Mon Sep 17 00:00:00 2001 From: kennytm Date: Fri, 6 Feb 2015 19:42:58 +0800 Subject: [PATCH] rustup. --- src/bits.rs | 8 ++++---- src/canvas.rs | 24 ++++++++++++------------ src/ec.rs | 6 +++--- src/lib.rs | 8 ++++---- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/bits.rs b/src/bits.rs index b798f35..13ee3b6 100644 --- a/src/bits.rs +++ b/src/bits.rs @@ -457,7 +457,7 @@ impl Bits { #[unstable] pub fn push_byte_data(&mut self, data: &[u8]) -> QrResult<()> { try!(self.push_header(Mode::Byte, data.len())); - for b in data.iter() { + for b in data { self.push_number(8, *b as u16); } Ok(()) @@ -754,7 +754,7 @@ mod finish_tests { impl Bits { /// Push a segmented data to the bits, and then terminate it. - pub fn push_segments(&mut self, data: &[u8], mut segments_iter: I) -> QrResult<()> + pub fn push_segments(&mut self, data: &[u8], segments_iter: I) -> QrResult<()> where I: Iterator { for segment in segments_iter { @@ -823,8 +823,8 @@ mod encode_tests { /// This method will not consider any Micro QR code versions. pub fn encode_auto(data: &[u8], ec_level: EcLevel) -> QrResult { let segments = Parser::new(data).collect::>(); - for version in [Version::Normal(9), Version::Normal(26), Version::Normal(40)].iter() { - let opt_segments = Optimizer::new(segments.iter().map(|s| *s), *version).collect::>(); + for version in &[Version::Normal(9), Version::Normal(26), Version::Normal(40)] { + let opt_segments = Optimizer::new(segments.iter().map(|s| *s), *version).collect::>(); let total_len = total_encoded_len(&*opt_segments, *version); let data_capacity = version.fetch(ec_level, &DATA_LENGTHS).unwrap(); if total_len <= data_capacity { diff --git a/src/canvas.rs b/src/canvas.rs index 47bcd3e..8700f63 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -111,9 +111,9 @@ impl Canvas { fn to_debug_str(&self) -> String { let width = self.width; let mut res = String::with_capacity((width * (width + 1)) as usize); - for y in (0 .. width) { + for y in 0 .. width { res.push('\n'); - for x in (0 .. width) { + for x in 0 .. width { res.push(match self.get(x, y) { Module::Empty => '?', Module::Light => '.', @@ -626,7 +626,7 @@ impl Canvas { coords: &[(i16, i16)]) { let zero: N = Int::zero(); let mut mask: N = !(!zero >> 1); - for &(x, y) in coords.iter() { + for &(x, y) in coords { let color = if (mask & number) == zero { off_color } else { on_color }; self.put(x, y, color); mask = mask >> 1; @@ -1428,8 +1428,8 @@ impl Canvas { /// patterns. pub fn apply_mask(&mut self, pattern: MaskPattern) { let mask_fn = get_mask_function(pattern); - for x in (0 .. self.width) { - for y in (0 .. self.width) { + for x in 0 .. self.width { + for y in 0 .. self.width { let module = self.get_mut(x, y); *module = module.mask(mask_fn(x, y)); } @@ -1587,15 +1587,15 @@ impl Canvas { fn compute_adjacent_penalty_score(&self, is_horizontal: bool) -> u16 { let mut total_score = 0; - for i in (0 .. self.width) { + for i in 0 .. self.width { let map_fn = |&:j| if is_horizontal { self.get(j, i) } else { self.get(i, j) }; - let mut colors = (0 .. self.width).map(map_fn) - .chain(Some(Module::Empty).into_iter()); + let colors = (0 .. self.width).map(map_fn) + .chain(Some(Module::Empty).into_iter()); let mut last_color = Module::Empty; let mut consecutive_len = 1u16; @@ -1623,8 +1623,8 @@ impl Canvas { fn compute_block_penalty_score(&self) -> u16 { let mut total_score = 0; - for i in (0 .. self.width-1) { - for j in (0 .. self.width-1) { + for i in 0 .. self.width-1 { + for j in 0 .. self.width-1 { let this = self.get(i, j); let right = self.get(i+1, j); let bottom = self.get(i, j+1); @@ -1651,8 +1651,8 @@ impl Canvas { let mut total_score = 0; - for i in (0 .. self.width) { - for j in (0 .. self.width-6) { + for i in 0 .. self.width { + for j in 0 .. self.width-6 { // TODO a ref to a closure should be enough? let get: Box Module> = if is_horizontal { Box::new(|&: k: i16| self.get(k, i)) diff --git a/src/ec.rs b/src/ec.rs index 3cf5234..68fe4eb 100644 --- a/src/ec.rs +++ b/src/ec.rs @@ -24,7 +24,7 @@ pub fn create_error_correction_code(data: &[u8], ec_code_size: usize) -> Vec let data_len = data.len(); let log_den = GENERATOR_POLYNOMIALS[ec_code_size]; - for i in (0 .. data_len) { + for i in 0 .. data_len { let lead_coeff = res[i] as usize; if lead_coeff == 0 { continue; @@ -76,8 +76,8 @@ mod ec_tests { fn interleave>(blocks: &Vec) -> Vec { let last_block_len = blocks.last().unwrap().len(); let mut res = Vec::with_capacity(last_block_len * blocks.len()); - for i in (0 .. last_block_len) { - for t in blocks.iter() { + for i in 0 .. last_block_len { + for t in blocks { if i < t.len() { res.push(t[i]); } diff --git a/src/lib.rs b/src/lib.rs index 7b4e8e9..5e45610 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,8 +8,8 @@ //! match code { //! Err(err) => panic!("Failed to encode the QR code: {:?}", err), //! Ok(code) => { -//! for y in (0 .. code.width()) { -//! for x in (0 .. code.width()) { +//! for y in 0 .. code.width() { +//! for x in 0 .. code.width() { //! let color = if code[(x, y)] { "black" } else { "white" }; //! // render color at position (x, y) //! } @@ -164,9 +164,9 @@ impl QrCode { let width = self.width; let mut k = 0; let mut res = String::with_capacity(width * (width + 1)); - for _ in (0 .. width) { + for _ in 0 .. width { res.push('\n'); - for _ in (0 .. width) { + for _ in 0 .. width { res.push(if self.content[k] { on_char } else { off_char }); k += 1; }