Skip to content

Commit b7214af

Browse files
committed
Rename the enum type Version to QrVersion.
Recent changes made enum names live in the type namespace as well. So we need to rename to avoid name conflict.
1 parent 191796f commit b7214af

File tree

6 files changed

+33
-30
lines changed

6 files changed

+33
-30
lines changed

src/bits.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use test::Bencher;
1010
use types::{QrResult, DataTooLong, UnsupportedCharacterSet, InvalidEciDesignator,
1111
InvalidCharacter,
1212
Mode, Numeric, Alphanumeric, Byte, Kanji,
13-
ErrorCorrectionLevel, Version, MicroVersion};
13+
ErrorCorrectionLevel, QrVersion, Version, MicroVersion};
1414
use optimize::{Parser, Optimizer, total_encoded_len, Segment};
1515

1616
//------------------------------------------------------------------------------
@@ -20,12 +20,12 @@ use optimize::{Parser, Optimizer, total_encoded_len, Segment};
2020
pub struct Bits {
2121
data: Vec<u8>,
2222
bit_offset: uint,
23-
version: Version,
23+
version: QrVersion,
2424
}
2525

2626
impl Bits {
2727
/// Constructs a new, empty bits structure.
28-
pub fn new(version: Version) -> Bits {
28+
pub fn new(version: QrVersion) -> Bits {
2929
Bits { data: Vec::new(), bit_offset: 0, version: version }
3030
}
3131

@@ -35,10 +35,8 @@ impl Bits {
3535
/// `n` bit in size. Otherwise the excess bits may stomp on the existing
3636
/// ones.
3737
fn push_number(&mut self, n: uint, number: u16) {
38-
/*
3938
debug_assert!(n == 16 || n < 16 && number < (1 << n),
4039
"{} is too big as a {}-bit number", number, n);
41-
*/
4240

4341
let b = self.bit_offset + n;
4442
match (self.bit_offset, b) {
@@ -99,7 +97,7 @@ impl Bits {
9997
}
10098

10199
/// Version of the QR code.
102-
pub fn version(&self) -> Version {
100+
pub fn version(&self) -> QrVersion {
103101
self.version
104102
}
105103
}
@@ -783,10 +781,12 @@ impl Bits {
783781
#[cfg(test)]
784782
mod encode_tests {
785783
use bits::Bits;
786-
use types::{Version, MicroVersion, DataTooLong, QrResult,
784+
use types::{QrVersion, Version, MicroVersion, DataTooLong, QrResult,
787785
L, Q, H, ErrorCorrectionLevel};
788786

789-
fn encode(data: &[u8], version: Version, ec_level: ErrorCorrectionLevel) -> QrResult<Vec<u8>> {
787+
fn encode(data: &[u8],
788+
version: QrVersion,
789+
ec_level: ErrorCorrectionLevel) -> QrResult<Vec<u8>> {
790790
let mut bits = Bits::new(version);
791791
try!(bits.push_optimal_data(data));
792792
try!(bits.push_terminator(ec_level));
@@ -846,7 +846,7 @@ pub fn encode_auto(data: &[u8], ec_level: ErrorCorrectionLevel) -> QrResult<Bits
846846
/// Finds the smallest version (QR code only) that can store N bits of data
847847
/// in the given error correction level.
848848
#[unstable]
849-
fn find_min_version(length: uint, ec_level: ErrorCorrectionLevel) -> Version {
849+
fn find_min_version(length: uint, ec_level: ErrorCorrectionLevel) -> QrVersion {
850850
let mut min = 0u;
851851
let mut max = 39u;
852852
while min < max {

src/canvas.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::iter::order::equals;
1414
use std::num::zero;
1515
use std::cmp::max;
1616

17-
use types::{Version, MicroVersion, ErrorCorrectionLevel, L, M, Q};
17+
use types::{QrVersion, Version, MicroVersion, ErrorCorrectionLevel, L, M, Q};
1818

1919
//------------------------------------------------------------------------------
2020
//{{{ Modules
@@ -84,7 +84,7 @@ pub struct Canvas {
8484
width: i16,
8585

8686
/// The version of the QR code.
87-
version: Version,
87+
version: QrVersion,
8888

8989
/// The error correction level of the QR code.
9090
ec_level: ErrorCorrectionLevel,
@@ -96,7 +96,7 @@ pub struct Canvas {
9696

9797
impl Canvas {
9898
/// Constructs a new canvas big enough for a QR code of the given version.
99-
pub fn new(version: Version, ec_level: ErrorCorrectionLevel) -> Canvas {
99+
pub fn new(version: QrVersion, ec_level: ErrorCorrectionLevel) -> Canvas {
100100
let width = version.width();
101101
Canvas {
102102
width: width,
@@ -945,7 +945,7 @@ struct DataModuleIter {
945945
}
946946

947947
impl DataModuleIter {
948-
fn new(version: Version) -> DataModuleIter {
948+
fn new(version: QrVersion) -> DataModuleIter {
949949
let width = version.width();
950950
DataModuleIter {
951951
x: width - 1,

src/ec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! The `ec` module applies the Reed-Solomon error correction codes.
22
3-
use types::{QrResult, Version, ErrorCorrectionLevel};
3+
use types::{QrResult, QrVersion, ErrorCorrectionLevel};
44

55
//------------------------------------------------------------------------------
66
//{{{ Error correction primitive
@@ -128,7 +128,7 @@ fn test_interleave() {
128128
/// Constructs data and error correction codewords ready to be put in the QR
129129
/// code matrix.
130130
pub fn construct_codewords(rawbits: &[u8],
131-
version: Version,
131+
version: QrVersion,
132132
ec_level: ErrorCorrectionLevel) -> QrResult<(Vec<u8>, Vec<u8>)> {
133133
let (block_1_size, block_1_count, block_2_size, block_2_count) =
134134
try!(version.fetch(ec_level, DATA_BYTES_PER_BLOCK.as_slice()));

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
extern crate test;
2424

2525
use std::slice::CloneableVector;
26-
pub use types::{QrResult, ErrorCorrectionLevel, L, M, Q, H, Version, MicroVersion};
26+
pub use types::{QrResult, ErrorCorrectionLevel, L, M, Q, H,
27+
QrVersion, Version, MicroVersion};
2728

2829
pub mod types;
2930
pub mod bits;
@@ -35,7 +36,7 @@ pub mod canvas;
3536
#[deriving(Clone)]
3637
pub struct QrCode {
3738
content: Vec<bool>,
38-
version: Version,
39+
version: QrVersion,
3940
ec_level: ErrorCorrectionLevel,
4041
width: uint,
4142
}
@@ -82,7 +83,7 @@ impl QrCode {
8283
/// let micro_code = QrCode::with_version(b"123", MicroVersion(1), L).unwrap();
8384
///
8485
pub fn with_version(data: &[u8],
85-
version: Version,
86+
version: QrVersion,
8687
ec_level: ErrorCorrectionLevel) -> QrResult<QrCode> {
8788
let mut bits = bits::Bits::new(version);
8889
try!(bits.push_optimal_data(data));
@@ -131,7 +132,7 @@ impl QrCode {
131132
}
132133

133134
/// Gets the version of this QR code.
134-
pub fn version(&self) -> Version {
135+
pub fn version(&self) -> QrVersion {
135136
self.version
136137
}
137138

src/optimize.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::slice::Items;
77
#[cfg(test)]
88
use test::Bencher;
99

10-
use types::{Mode, Version, Numeric, Alphanumeric, Byte, Kanji};
10+
use types::{Mode, QrVersion, Numeric, Alphanumeric, Byte, Kanji};
1111

1212
//------------------------------------------------------------------------------
1313
//{{{ Segment
@@ -28,7 +28,7 @@ pub struct Segment {
2828
impl Segment {
2929
/// Compute the number of bits (including the size of the mode indicator and
3030
/// length bits) when this segment is encoded.
31-
pub fn encoded_len(&self, version: Version) -> uint {
31+
pub fn encoded_len(&self, version: QrVersion) -> uint {
3232
let byte_size = self.end - self.begin;
3333
let chars_count = if self.mode == Kanji { byte_size / 2 } else { byte_size };
3434

@@ -228,7 +228,7 @@ pub struct Optimizer<I> {
228228
parser: I,
229229
last_segment: Segment,
230230
last_segment_size: uint,
231-
version: Version,
231+
version: QrVersion,
232232
ended: bool,
233233
}
234234

@@ -239,7 +239,7 @@ impl<I: Iterator<Segment>> Optimizer<I> {
239239
/// left to right until the new segment is longer than before. This method
240240
/// does *not* use Annex J from the ISO standard.
241241
///
242-
pub fn new(mut segments: I, version: Version) -> Optimizer<I> {
242+
pub fn new(mut segments: I, version: QrVersion) -> Optimizer<I> {
243243
match segments.next() {
244244
None => Optimizer {
245245
parser: segments,
@@ -260,7 +260,7 @@ impl<I: Iterator<Segment>> Optimizer<I> {
260260
}
261261

262262
impl<'a> Parser<'a> {
263-
pub fn optimize(self, version: Version) -> Optimizer<Parser<'a>> {
263+
pub fn optimize(self, version: QrVersion) -> Optimizer<Parser<'a>> {
264264
Optimizer::new(self, version)
265265
}
266266
}
@@ -303,17 +303,17 @@ impl<I: Iterator<Segment>> Iterator<Segment> for Optimizer<I> {
303303
}
304304

305305
/// Computes the total encoded length of all segments.
306-
pub fn total_encoded_len(segments: &[Segment], version: Version) -> uint {
306+
pub fn total_encoded_len(segments: &[Segment], version: QrVersion) -> uint {
307307
use std::iter::AdditiveIterator;
308308
segments.iter().map(|seg| seg.encoded_len(version)).sum()
309309
}
310310

311311
#[cfg(test)]
312312
mod optimize_tests {
313313
use optimize::{Optimizer, total_encoded_len, Segment};
314-
use types::{Numeric, Alphanumeric, Byte, Kanji, Version, MicroVersion};
314+
use types::{Numeric, Alphanumeric, Byte, Kanji, QrVersion, Version, MicroVersion};
315315

316-
fn test_optimization_result(given: Vec<Segment>, expected: Vec<Segment>, version: Version) {
316+
fn test_optimization_result(given: Vec<Segment>, expected: Vec<Segment>, version: QrVersion) {
317317
let prev_len = total_encoded_len(given.as_slice(), version);
318318
let opt_segs = Optimizer::new(given.iter().map(|seg| *seg), version).collect::<Vec<Segment>>();
319319
let new_len = total_encoded_len(opt_segs.as_slice(), version);
@@ -437,6 +437,8 @@ mod optimize_tests {
437437

438438
#[bench]
439439
fn bench_optimize(bencher: &mut Bencher) {
440+
use types::Version;
441+
440442
let data = b"QR\x83R\x81[\x83h\x81i\x83L\x83\x85\x81[\x83A\x81[\x83\x8b\x83R\x81[\x83h\x81j\x82\xc6\x82\xcd\x81A1994\x94N\x82\xc9\x83f\x83\x93\x83\\\x81[\x82\xcc\x8aJ\x94\xad\x95\x94\x96\xe5\x81i\x8c\xbb\x8d\xdd\x82\xcd\x95\xaa\x97\xa3\x82\xb5\x83f\x83\x93\x83\\\x81[\x83E\x83F\x81[\x83u\x81j\x82\xaa\x8aJ\x94\xad\x82\xb5\x82\xbd\x83}\x83g\x83\x8a\x83b\x83N\x83X\x8c^\x93\xf1\x8e\x9f\x8c\xb3\x83R\x81[\x83h\x82\xc5\x82\xa0\x82\xe9\x81B\x82\xc8\x82\xa8\x81AQR\x83R\x81[\x83h\x82\xc6\x82\xa2\x82\xa4\x96\xbc\x8f\xcc\x81i\x82\xa8\x82\xe6\x82\xd1\x92P\x8c\xea\x81j\x82\xcd\x83f\x83\x93\x83\\\x81[\x83E\x83F\x81[\x83u\x82\xcc\x93o\x98^\x8f\xa4\x95W\x81i\x91\xe64075066\x8d\x86\x81j\x82\xc5\x82\xa0\x82\xe9\x81BQR\x82\xcdQuick Response\x82\xc9\x97R\x97\x88\x82\xb5\x81A\x8d\x82\x91\xac\x93\xc7\x82\xdd\x8e\xe6\x82\xe8\x82\xaa\x82\xc5\x82\xab\x82\xe9\x82\xe6\x82\xa4\x82\xc9\x8aJ\x94\xad\x82\xb3\x82\xea\x82\xbd\x81B\x93\x96\x8f\x89\x82\xcd\x8e\xa9\x93\xae\x8e\xd4\x95\x94\x95i\x8dH\x8f\xea\x82\xe2\x94z\x91\x97\x83Z\x83\x93\x83^\x81[\x82\xc8\x82\xc7\x82\xc5\x82\xcc\x8eg\x97p\x82\xf0\x94O\x93\xaa\x82\xc9\x8aJ\x94\xad\x82\xb3\x82\xea\x82\xbd\x82\xaa\x81A\x8c\xbb\x8d\xdd\x82\xc5\x82\xcd\x83X\x83}\x81[\x83g\x83t\x83H\x83\x93\x82\xcc\x95\x81\x8by\x82\xc8\x82\xc7\x82\xc9\x82\xe6\x82\xe8\x93\xfa\x96{\x82\xc9\x8c\xc0\x82\xe7\x82\xb8\x90\xa2\x8aE\x93I\x82\xc9\x95\x81\x8by\x82\xb5\x82\xc4\x82\xa2\x82\xe9\x81B";
441443
bencher.iter(|| {
442444
Parser::new(data).optimize(Version(15))

src/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub enum ErrorCorrectionLevel {
6565
/// `Version(40)` of size 177×177.
6666
#[unstable]
6767
#[deriving(Show, PartialEq, Eq, Copy, Clone)]
68-
pub enum Version {
68+
pub enum QrVersion {
6969
/// A normal QR code version. The parameter should be between 1 and 40.
7070
#[unstable]
7171
Version(i16),
@@ -74,7 +74,7 @@ pub enum Version {
7474
MicroVersion(i16),
7575
}
7676

77-
impl Version {
77+
impl QrVersion {
7878
/// Get the number of "modules" on each size of the QR code, i.e. the width
7979
/// and height of the code.
8080
#[unstable]
@@ -163,7 +163,7 @@ impl Mode {
163163
/// This method will return `Err(UnsupportedCharacterSet)` if the is not
164164
/// supported in the given version.
165165
#[unstable]
166-
pub fn length_bits_count(&self, version: Version) -> uint {
166+
pub fn length_bits_count(&self, version: QrVersion) -> uint {
167167
match version {
168168
MicroVersion(a) => {
169169
let a = a as uint;

0 commit comments

Comments
 (0)