Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add .mode option to QRBuilder #56

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fast_qr"
version = "0.12.3"
version = "0.12.4"
authors = ["erwan.vivien <[email protected]>"]
edition = "2021"
description = "Generates optimized QRCode"
Expand Down
18 changes: 10 additions & 8 deletions src/qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ impl QRCode {
input: &[u8],
ecl: Option<ECL>,
v: Option<Version>,
mode: Option<Mode>,
mut mask: Option<Mask>,
) -> Result<Self, QRCodeError> {
use crate::placement::create_matrix;

let mode = encode::best_encoding(input);
let mode = mode.unwrap_or_else(|| encode::best_encoding(input));
let level = ecl.unwrap_or(ECL::Q);

let version = match Version::get(mode, level, input.len()) {
Expand Down Expand Up @@ -199,7 +200,7 @@ impl QRCode {
pub struct QRBuilder {
input: Vec<u8>,
ecl: Option<ECL>,
// mode: Option<Mode>,
mode: Option<Mode>,
version: Option<Version>,
mask: Option<Mask>,
}
Expand All @@ -211,16 +212,17 @@ impl QRBuilder {
QRBuilder {
input: input.into(),
mask: None,
// mode: None,
mode: None,
version: None,
ecl: None,
}
}

// pub fn mode(&mut self, mode: Mode) -> &mut Self {
// self.mode = Some(mode);
// self
// }
/// Forces the Mode
pub fn mode(&mut self, mode: Mode) -> &mut Self {
self.mode = Some(mode);
self
}

/// Forces the Encoding Level
pub fn ecl(&mut self, ecl: ECL) -> &mut Self {
Expand All @@ -246,6 +248,6 @@ impl QRBuilder {
/// - `QRCodeError::EncodedData` if `input` is too large to be encoded. See [an online table](https://fast-qr.com/blog/tables/ecl) for more info.
/// - `QRCodeError::SpecifiedVersion` if specified `version` is too small to contain data
pub fn build(&self) -> Result<QRCode, QRCodeError> {
QRCode::new(&self.input, self.ecl, self.version, self.mask)
QRCode::new(&self.input, self.ecl, self.version, self.mode, self.mask)
}
}
Loading