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.
This commit is contained in:
parent
191796f759
commit
b7214af165
18
src/bits.rs
18
src/bits.rs
|
@ -10,7 +10,7 @@ use test::Bencher;
|
|||
use types::{QrResult, DataTooLong, UnsupportedCharacterSet, InvalidEciDesignator,
|
||||
InvalidCharacter,
|
||||
Mode, Numeric, Alphanumeric, Byte, Kanji,
|
||||
ErrorCorrectionLevel, Version, MicroVersion};
|
||||
ErrorCorrectionLevel, QrVersion, Version, MicroVersion};
|
||||
use optimize::{Parser, Optimizer, total_encoded_len, Segment};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -20,12 +20,12 @@ use optimize::{Parser, Optimizer, total_encoded_len, Segment};
|
|||
pub struct Bits {
|
||||
data: Vec<u8>,
|
||||
bit_offset: uint,
|
||||
version: Version,
|
||||
version: QrVersion,
|
||||
}
|
||||
|
||||
impl Bits {
|
||||
/// Constructs a new, empty bits structure.
|
||||
pub fn new(version: Version) -> Bits {
|
||||
pub fn new(version: QrVersion) -> Bits {
|
||||
Bits { data: Vec::new(), bit_offset: 0, version: version }
|
||||
}
|
||||
|
||||
|
@ -35,10 +35,8 @@ impl Bits {
|
|||
/// `n` bit in size. Otherwise the excess bits may stomp on the existing
|
||||
/// ones.
|
||||
fn push_number(&mut self, n: uint, number: u16) {
|
||||
/*
|
||||
debug_assert!(n == 16 || n < 16 && number < (1 << n),
|
||||
"{} is too big as a {}-bit number", number, n);
|
||||
*/
|
||||
|
||||
let b = self.bit_offset + n;
|
||||
match (self.bit_offset, b) {
|
||||
|
@ -99,7 +97,7 @@ impl Bits {
|
|||
}
|
||||
|
||||
/// Version of the QR code.
|
||||
pub fn version(&self) -> Version {
|
||||
pub fn version(&self) -> QrVersion {
|
||||
self.version
|
||||
}
|
||||
}
|
||||
|
@ -783,10 +781,12 @@ impl Bits {
|
|||
#[cfg(test)]
|
||||
mod encode_tests {
|
||||
use bits::Bits;
|
||||
use types::{Version, MicroVersion, DataTooLong, QrResult,
|
||||
use types::{QrVersion, Version, MicroVersion, DataTooLong, QrResult,
|
||||
L, Q, H, ErrorCorrectionLevel};
|
||||
|
||||
fn encode(data: &[u8], version: Version, ec_level: ErrorCorrectionLevel) -> QrResult<Vec<u8>> {
|
||||
fn encode(data: &[u8],
|
||||
version: QrVersion,
|
||||
ec_level: ErrorCorrectionLevel) -> QrResult<Vec<u8>> {
|
||||
let mut bits = Bits::new(version);
|
||||
try!(bits.push_optimal_data(data));
|
||||
try!(bits.push_terminator(ec_level));
|
||||
|
@ -846,7 +846,7 @@ pub fn encode_auto(data: &[u8], ec_level: ErrorCorrectionLevel) -> QrResult<Bits
|
|||
/// Finds the smallest version (QR code only) that can store N bits of data
|
||||
/// in the given error correction level.
|
||||
#[unstable]
|
||||
fn find_min_version(length: uint, ec_level: ErrorCorrectionLevel) -> Version {
|
||||
fn find_min_version(length: uint, ec_level: ErrorCorrectionLevel) -> QrVersion {
|
||||
let mut min = 0u;
|
||||
let mut max = 39u;
|
||||
while min < max {
|
||||
|
|
|
@ -14,7 +14,7 @@ use std::iter::order::equals;
|
|||
use std::num::zero;
|
||||
use std::cmp::max;
|
||||
|
||||
use types::{Version, MicroVersion, ErrorCorrectionLevel, L, M, Q};
|
||||
use types::{QrVersion, Version, MicroVersion, ErrorCorrectionLevel, L, M, Q};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//{{{ Modules
|
||||
|
@ -84,7 +84,7 @@ pub struct Canvas {
|
|||
width: i16,
|
||||
|
||||
/// The version of the QR code.
|
||||
version: Version,
|
||||
version: QrVersion,
|
||||
|
||||
/// The error correction level of the QR code.
|
||||
ec_level: ErrorCorrectionLevel,
|
||||
|
@ -96,7 +96,7 @@ pub struct Canvas {
|
|||
|
||||
impl Canvas {
|
||||
/// Constructs a new canvas big enough for a QR code of the given version.
|
||||
pub fn new(version: Version, ec_level: ErrorCorrectionLevel) -> Canvas {
|
||||
pub fn new(version: QrVersion, ec_level: ErrorCorrectionLevel) -> Canvas {
|
||||
let width = version.width();
|
||||
Canvas {
|
||||
width: width,
|
||||
|
@ -945,7 +945,7 @@ struct DataModuleIter {
|
|||
}
|
||||
|
||||
impl DataModuleIter {
|
||||
fn new(version: Version) -> DataModuleIter {
|
||||
fn new(version: QrVersion) -> DataModuleIter {
|
||||
let width = version.width();
|
||||
DataModuleIter {
|
||||
x: width - 1,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! The `ec` module applies the Reed-Solomon error correction codes.
|
||||
|
||||
use types::{QrResult, Version, ErrorCorrectionLevel};
|
||||
use types::{QrResult, QrVersion, ErrorCorrectionLevel};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//{{{ Error correction primitive
|
||||
|
@ -128,7 +128,7 @@ fn test_interleave() {
|
|||
/// Constructs data and error correction codewords ready to be put in the QR
|
||||
/// code matrix.
|
||||
pub fn construct_codewords(rawbits: &[u8],
|
||||
version: Version,
|
||||
version: QrVersion,
|
||||
ec_level: ErrorCorrectionLevel) -> QrResult<(Vec<u8>, Vec<u8>)> {
|
||||
let (block_1_size, block_1_count, block_2_size, block_2_count) =
|
||||
try!(version.fetch(ec_level, DATA_BYTES_PER_BLOCK.as_slice()));
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
extern crate test;
|
||||
|
||||
use std::slice::CloneableVector;
|
||||
pub use types::{QrResult, ErrorCorrectionLevel, L, M, Q, H, Version, MicroVersion};
|
||||
pub use types::{QrResult, ErrorCorrectionLevel, L, M, Q, H,
|
||||
QrVersion, Version, MicroVersion};
|
||||
|
||||
pub mod types;
|
||||
pub mod bits;
|
||||
|
@ -35,7 +36,7 @@ pub mod canvas;
|
|||
#[deriving(Clone)]
|
||||
pub struct QrCode {
|
||||
content: Vec<bool>,
|
||||
version: Version,
|
||||
version: QrVersion,
|
||||
ec_level: ErrorCorrectionLevel,
|
||||
width: uint,
|
||||
}
|
||||
|
@ -82,7 +83,7 @@ impl QrCode {
|
|||
/// let micro_code = QrCode::with_version(b"123", MicroVersion(1), L).unwrap();
|
||||
///
|
||||
pub fn with_version(data: &[u8],
|
||||
version: Version,
|
||||
version: QrVersion,
|
||||
ec_level: ErrorCorrectionLevel) -> QrResult<QrCode> {
|
||||
let mut bits = bits::Bits::new(version);
|
||||
try!(bits.push_optimal_data(data));
|
||||
|
@ -131,7 +132,7 @@ impl QrCode {
|
|||
}
|
||||
|
||||
/// Gets the version of this QR code.
|
||||
pub fn version(&self) -> Version {
|
||||
pub fn version(&self) -> QrVersion {
|
||||
self.version
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::slice::Items;
|
|||
#[cfg(test)]
|
||||
use test::Bencher;
|
||||
|
||||
use types::{Mode, Version, Numeric, Alphanumeric, Byte, Kanji};
|
||||
use types::{Mode, QrVersion, Numeric, Alphanumeric, Byte, Kanji};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//{{{ Segment
|
||||
|
@ -28,7 +28,7 @@ pub struct Segment {
|
|||
impl Segment {
|
||||
/// Compute the number of bits (including the size of the mode indicator and
|
||||
/// length bits) when this segment is encoded.
|
||||
pub fn encoded_len(&self, version: Version) -> uint {
|
||||
pub fn encoded_len(&self, version: QrVersion) -> uint {
|
||||
let byte_size = self.end - self.begin;
|
||||
let chars_count = if self.mode == Kanji { byte_size / 2 } else { byte_size };
|
||||
|
||||
|
@ -228,7 +228,7 @@ pub struct Optimizer<I> {
|
|||
parser: I,
|
||||
last_segment: Segment,
|
||||
last_segment_size: uint,
|
||||
version: Version,
|
||||
version: QrVersion,
|
||||
ended: bool,
|
||||
}
|
||||
|
||||
|
@ -239,7 +239,7 @@ impl<I: Iterator<Segment>> Optimizer<I> {
|
|||
/// left to right until the new segment is longer than before. This method
|
||||
/// does *not* use Annex J from the ISO standard.
|
||||
///
|
||||
pub fn new(mut segments: I, version: Version) -> Optimizer<I> {
|
||||
pub fn new(mut segments: I, version: QrVersion) -> Optimizer<I> {
|
||||
match segments.next() {
|
||||
None => Optimizer {
|
||||
parser: segments,
|
||||
|
@ -260,7 +260,7 @@ impl<I: Iterator<Segment>> Optimizer<I> {
|
|||
}
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
pub fn optimize(self, version: Version) -> Optimizer<Parser<'a>> {
|
||||
pub fn optimize(self, version: QrVersion) -> Optimizer<Parser<'a>> {
|
||||
Optimizer::new(self, version)
|
||||
}
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ impl<I: Iterator<Segment>> Iterator<Segment> for Optimizer<I> {
|
|||
}
|
||||
|
||||
/// Computes the total encoded length of all segments.
|
||||
pub fn total_encoded_len(segments: &[Segment], version: Version) -> uint {
|
||||
pub fn total_encoded_len(segments: &[Segment], version: QrVersion) -> uint {
|
||||
use std::iter::AdditiveIterator;
|
||||
segments.iter().map(|seg| seg.encoded_len(version)).sum()
|
||||
}
|
||||
|
@ -311,9 +311,9 @@ pub fn total_encoded_len(segments: &[Segment], version: Version) -> uint {
|
|||
#[cfg(test)]
|
||||
mod optimize_tests {
|
||||
use optimize::{Optimizer, total_encoded_len, Segment};
|
||||
use types::{Numeric, Alphanumeric, Byte, Kanji, Version, MicroVersion};
|
||||
use types::{Numeric, Alphanumeric, Byte, Kanji, QrVersion, Version, MicroVersion};
|
||||
|
||||
fn test_optimization_result(given: Vec<Segment>, expected: Vec<Segment>, version: Version) {
|
||||
fn test_optimization_result(given: Vec<Segment>, expected: Vec<Segment>, version: QrVersion) {
|
||||
let prev_len = total_encoded_len(given.as_slice(), version);
|
||||
let opt_segs = Optimizer::new(given.iter().map(|seg| *seg), version).collect::<Vec<Segment>>();
|
||||
let new_len = total_encoded_len(opt_segs.as_slice(), version);
|
||||
|
@ -437,6 +437,8 @@ mod optimize_tests {
|
|||
|
||||
#[bench]
|
||||
fn bench_optimize(bencher: &mut Bencher) {
|
||||
use types::Version;
|
||||
|
||||
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";
|
||||
bencher.iter(|| {
|
||||
Parser::new(data).optimize(Version(15))
|
||||
|
|
|
@ -65,7 +65,7 @@ pub enum ErrorCorrectionLevel {
|
|||
/// `Version(40)` of size 177×177.
|
||||
#[unstable]
|
||||
#[deriving(Show, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum Version {
|
||||
pub enum QrVersion {
|
||||
/// A normal QR code version. The parameter should be between 1 and 40.
|
||||
#[unstable]
|
||||
Version(i16),
|
||||
|
@ -74,7 +74,7 @@ pub enum Version {
|
|||
MicroVersion(i16),
|
||||
}
|
||||
|
||||
impl Version {
|
||||
impl QrVersion {
|
||||
/// Get the number of "modules" on each size of the QR code, i.e. the width
|
||||
/// and height of the code.
|
||||
#[unstable]
|
||||
|
@ -163,7 +163,7 @@ impl Mode {
|
|||
/// This method will return `Err(UnsupportedCharacterSet)` if the is not
|
||||
/// supported in the given version.
|
||||
#[unstable]
|
||||
pub fn length_bits_count(&self, version: Version) -> uint {
|
||||
pub fn length_bits_count(&self, version: QrVersion) -> uint {
|
||||
match version {
|
||||
MicroVersion(a) => {
|
||||
let a = a as uint;
|
||||
|
|
Loading…
Reference in a new issue