Skip to content

Commit ad77fe2

Browse files
committed
fix: Mode was not public
1 parent 4c0a798 commit ad77fe2

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

examples/simple.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ fn main() {
44
let qrcode = QRBuilder::new("https://example.com/")
55
.ecl(ECL::H)
66
.version(Version::V03)
7+
.mode(fast_qr::Mode::Numeric)
78
.build()
89
.unwrap();
910

src/encode.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ use crate::version::Version;
1111
/// Enum for the 3 encoding mode
1212
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
1313
pub enum Mode {
14+
/// Numeric mode (0-9 only)
1415
Numeric,
16+
/// Alphanumeric mode (0-9, A-Z, $%*./:+-?.= [space])
1517
Alphanumeric,
18+
/// Byte mode (any)
1619
Byte,
1720
}
1821

@@ -152,7 +155,12 @@ fn pad_to_8(compact: &mut CompactQR) {
152155

153156
/// Converts ascii number to it's value in usize \
154157
/// "5" -> 5
155-
const fn ascii_to_digit(c: u8) -> usize {
158+
fn ascii_to_digit(c: u8) -> usize {
159+
assert!(
160+
c.is_ascii_digit(),
161+
"Unexpected character '{}' in Numeric mode",
162+
c as char
163+
);
156164
(c - b'0') as usize
157165
}
158166

@@ -172,7 +180,7 @@ pub(crate) fn ascii_to_alphanumeric(c: u8) -> usize {
172180
b'.' => 42,
173181
b'/' => 43,
174182
b':' => 44,
175-
_ => panic!("Character '{}' should not occur", c as char), // unreachable!()
183+
_ => panic!("Unexpected haracter '{}' in Alphanumeric mode", c as char),
176184
}
177185
}
178186

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
7575
pub use crate::datamasking::Mask;
7676
pub use crate::ecl::ECL;
77+
pub use crate::encode::Mode;
7778
pub use crate::module::{Module, ModuleType};
7879
pub use crate::qr::{QRBuilder, QRCode};
7980
pub use crate::version::Version;

0 commit comments

Comments
 (0)