Skip to content

Commit

Permalink
feat: add .mode option to QRBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanvivien committed May 7, 2024
1 parent 62797a8 commit 1be4a87
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 74 deletions.
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(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

0 comments on commit 1be4a87

Please sign in to comment.