Skip to content

Commit 4d2032e

Browse files
committed
rustup.
Restructure Canvas::draw_data(), since change in rust-lang/rust#17403 no longer allows returning a mutable ref directly.
1 parent e6b80da commit 4d2032e

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

src/canvas.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,38 +1163,42 @@ mod data_iter_tests {
11631163
//------------------------------------------------------------------------------
11641164
//{{{ Data placement
11651165

1166-
fn draw_codewords<'a, I>(codewords: &[u8], is_half_codeword_at_end: bool, modules: &mut I)
1167-
where I: Iterator<&'a mut Module>
1168-
{
1169-
let length = codewords.len();
1170-
let last_word = if is_half_codeword_at_end { length-1 } else { length };
1171-
for (i, b) in codewords.iter().enumerate() {
1172-
let bits_end = if i == last_word { 4 } else { 0 };
1173-
for j in range_inclusive(bits_end, 7u).rev() {
1174-
let color = if (*b & (1 << j)) != 0 { DarkUnmasked } else { LightUnmasked };
1175-
match modules.next() {
1176-
Some(module) => { *module = color; }
1177-
None => { return; }
1166+
impl Canvas {
1167+
fn draw_codewords<'a, I>(&mut self,
1168+
codewords: &[u8],
1169+
is_half_codeword_at_end: bool,
1170+
coords: &mut I)
1171+
where I: Iterator<(i16, i16)>
1172+
{
1173+
let length = codewords.len();
1174+
let last_word = if is_half_codeword_at_end { length-1 } else { length };
1175+
for (i, b) in codewords.iter().enumerate() {
1176+
let bits_end = if i == last_word { 4 } else { 0 };
1177+
'outside:
1178+
for j in range_inclusive(bits_end, 7u).rev() {
1179+
let color = if (*b & (1 << j)) != 0 { DarkUnmasked } else { LightUnmasked };
1180+
while let Some((x, y)) = coords.next() {
1181+
let r = self.get_mut(x, y);
1182+
if *r == Empty {
1183+
*r = color;
1184+
continue 'outside;
1185+
}
1186+
}
1187+
return;
11781188
}
11791189
}
11801190
}
1181-
}
11821191

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

1191-
let mut coords = DataModuleIter::new(self.version)
1192-
.filter_map(|(x, y)| {
1193-
let r = self.get_mut(x, y);
1194-
if *r != Empty { None } else { Some(r) }
1195-
});
1196-
draw_codewords(data, is_half_codeword_at_end, &mut coords);
1197-
draw_codewords(ec, false, &mut coords);
1199+
let mut coords = DataModuleIter::new(self.version);
1200+
self.draw_codewords(data, is_half_codeword_at_end, &mut coords);
1201+
self.draw_codewords(ec, false, &mut coords);
11981202
}
11991203
}
12001204

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
#![unstable]
2222
#![feature(slicing_syntax)]
23+
#![feature(while_let)]
2324

2425
extern crate test;
2526

@@ -176,10 +177,6 @@ impl CloneableVector<bool> for QrCode {
176177
fn to_vec(&self) -> Vec<bool> {
177178
self.content.clone()
178179
}
179-
180-
fn into_vec(self) -> Vec<bool> {
181-
self.content
182-
}
183180
}
184181

185182
#[cfg(test)]

0 commit comments

Comments
 (0)