pub struct QrCodeBuilder<D: AsRef<[u8]>> { /* private fields */ }Expand description
A builder for QrCode, offering ergonomic, chainable configuration.
Construct one with QrCode::builder. The builder delegates to the
existing constructors, so its output is identical to calling them directly.
Implementations§
Source§impl<D: AsRef<[u8]>> QrCodeBuilder<D>
impl<D: AsRef<[u8]>> QrCodeBuilder<D>
Sourcepub fn ec_level(self, ec_level: EcLevel) -> Self
pub fn ec_level(self, ec_level: EcLevel) -> Self
Sets the error correction level (default EcLevel::M).
Sourcepub fn version(self, version: Version) -> Self
pub fn version(self, version: Version) -> Self
Pins a specific QR Version. When set, build() behaves like
QrCode::with_version. If micro is also set, the
explicit version takes precedence.
Sourcepub fn micro(self, yes: bool) -> Self
pub fn micro(self, yes: bool) -> Self
Requests a Micro QR code (the smallest fitting Micro version), behaving
like QrCode::micro_with_error_correction_level when no explicit
version is set.
Sourcepub fn encoding_mode(self, mode: Mode) -> Self
pub fn encoding_mode(self, mode: Mode) -> Self
Hints the encoding Mode (e.g. Mode::Byte), bypassing automatic
mode optimization. When a version is also set it is
used directly; otherwise the smallest fitting version for that mode is
auto-selected.
The data must be encodable in the chosen mode: Mode::Kanji validates
its Shift-JIS pairs and Mode::Byte accepts anything, but
Mode::Numeric / Mode::Alphanumeric assume their input already
matches (as automatic optimization would never select them otherwise).
Sourcepub fn encoding_mode_typed<M: EncodingMode>(self) -> QrResult<Self>
pub fn encoding_mode_typed<M: EncodingMode>(self) -> QrResult<Self>
Hints the encoding mode with a type-level EncodingMode marker.
Unlike encoding_mode, this validates data
immediately and returns QrError::InvalidCharacter when the selected
mode cannot represent it.
use qrcode_rs::{NumericMode, QrCode, QrError, Version};
let code = QrCode::builder(b"01234567")
.version(Version::Normal(1))
.encoding_mode_typed::<NumericMode>()
.unwrap()
.build()
.unwrap();
assert_eq!(code.version(), Version::Normal(1));
let err = QrCode::builder(b"12a")
.encoding_mode_typed::<NumericMode>()
.unwrap_err();
assert_eq!(err, QrError::InvalidCharacter { position: 2, byte: b'a' });§Errors
Returns QrError::InvalidCharacter with the first invalid byte when
data is not valid for M.
Sourcepub fn force_mode(self, mode: Mode) -> Self
pub fn force_mode(self, mode: Mode) -> Self
Forces a specific encoding Mode, bypassing automatic optimization.
This is an alias for encoding_mode, provided for
familiarity with the QR-code vocabulary.
Sourcepub fn force_mode_typed<M: EncodingMode>(self) -> QrResult<Self>
pub fn force_mode_typed<M: EncodingMode>(self) -> QrResult<Self>
Forces a type-level encoding mode after validating the input.
This is an alias for encoding_mode_typed.
§Errors
Returns QrError::InvalidCharacter with the first invalid byte when
data is not valid for M.