Skip to content

Commit

Permalink
rustup.
Browse files Browse the repository at this point in the history
Restructure Canvas::draw_data(), since change in rust-lang/rust#17403 no
longer allows returning a mutable ref directly.
  • Loading branch information
kennytm committed Oct 23, 2014
1 parent e6b80da commit 4d2032e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
46 changes: 25 additions & 21 deletions src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,38 +1163,42 @@ mod data_iter_tests {
//------------------------------------------------------------------------------
//{{{ Data placement

fn draw_codewords<'a, I>(codewords: &[u8], is_half_codeword_at_end: bool, modules: &mut I)
where I: Iterator<&'a mut Module>
{
let length = codewords.len();
let last_word = if is_half_codeword_at_end { length-1 } else { length };
for (i, b) in codewords.iter().enumerate() {
let bits_end = if i == last_word { 4 } else { 0 };
for j in range_inclusive(bits_end, 7u).rev() {
let color = if (*b & (1 << j)) != 0 { DarkUnmasked } else { LightUnmasked };
match modules.next() {
Some(module) => { *module = color; }
None => { return; }
impl Canvas {
fn draw_codewords<'a, I>(&mut self,
codewords: &[u8],
is_half_codeword_at_end: bool,
coords: &mut I)
where I: Iterator<(i16, i16)>
{
let length = codewords.len();
let last_word = if is_half_codeword_at_end { length-1 } else { length };
for (i, b) in codewords.iter().enumerate() {
let bits_end = if i == last_word { 4 } else { 0 };
'outside:
for j in range_inclusive(bits_end, 7u).rev() {
let color = if (*b & (1 << j)) != 0 { DarkUnmasked } else { LightUnmasked };
while let Some((x, y)) = coords.next() {
let r = self.get_mut(x, y);
if *r == Empty {
*r = color;
continue 'outside;
}
}
return;
}
}
}
}

impl Canvas {
/// Draws the encoded data and error correction codes to the empty modules.
pub fn draw_data(&mut self, data: &[u8], ec: &[u8]) {
let is_half_codeword_at_end = match (self.version, self.ec_level) {
(MicroVersion(1), L) | (MicroVersion(3), M) => true,
_ => false,
};

let mut coords = DataModuleIter::new(self.version)
.filter_map(|(x, y)| {
let r = self.get_mut(x, y);
if *r != Empty { None } else { Some(r) }
});
draw_codewords(data, is_half_codeword_at_end, &mut coords);
draw_codewords(ec, false, &mut coords);
let mut coords = DataModuleIter::new(self.version);
self.draw_codewords(data, is_half_codeword_at_end, &mut coords);
self.draw_codewords(ec, false, &mut coords);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#![unstable]
#![feature(slicing_syntax)]
#![feature(while_let)]

extern crate test;

Expand Down Expand Up @@ -176,10 +177,6 @@ impl CloneableVector<bool> for QrCode {
fn to_vec(&self) -> Vec<bool> {
self.content.clone()
}

fn into_vec(self) -> Vec<bool> {
self.content
}
}

#[cfg(test)]
Expand Down

0 comments on commit 4d2032e

Please sign in to comment.