pub struct QrCodeBuilder<'a, 'b> { /* private fields */ }
Expand description
Builder for generating QR Codes.
Generates a QR Code in the form of a Result<Vec<u8>, Error>
and overlay a logo on top of it.
The Vec<u8>
is generated according to image::ImageOutputFormat::Png
.
§Argument requirements
- The
content
should not be empty. - The
size
should be betweenSIZE_MIN
andSIZE_MAX
(their values might change in future releases).
Note that these are only checked in QrCodeBuilder::build
.
§Defaults
bg_color
andlogo_bg_color
default to white.size
defaults toDEFAULT_SIZE
.
§Examples
let logo = include_bytes!("../../assets/logo.png");
use qr_rs_lib::{QrCodeBuilder, Rgb};
let qr_code = QrCodeBuilder::new("github.com", logo)
.with_size(600)
.with_bg_color(Rgb([255, 0, 0]))
.build();
assert!(matches!(qr_code, Ok(_)));
Implementations§
Source§impl<'a, 'b> QrCodeBuilder<'a, 'b>
impl<'a, 'b> QrCodeBuilder<'a, 'b>
Sourcepub const fn new(content: &'a str, logo: &'b [u8]) -> QrCodeBuilder<'a, 'b>
pub const fn new(content: &'a str, logo: &'b [u8]) -> QrCodeBuilder<'a, 'b>
Construct a new QR Code builder given the contents of the QR Code and the logo to use.
Everything else is optional.
Sourcepub fn with_size(&mut self, size: u32) -> &mut Self
pub fn with_size(&mut self, size: u32) -> &mut Self
Sets the dimensions of the QR Code to size x size
.
Sourcepub fn with_bg_color(&mut self, bg_color: Rgb) -> &mut Self
pub fn with_bg_color(&mut self, bg_color: Rgb) -> &mut Self
Sets the background color of the QR Code. The caller is responsible for ensuring that the end result is readable.
Defaults to white.
Sourcepub fn with_logo_bg_color(&mut self, logo_bg_color: Rgb) -> &mut Self
pub fn with_logo_bg_color(&mut self, logo_bg_color: Rgb) -> &mut Self
Sets the background color of the padding around the logo. The caller is responsible for ensuring that the end result is readable.
Defaults to white.
Trait Implementations§
Auto Trait Implementations§
impl<'a, 'b> Freeze for QrCodeBuilder<'a, 'b>
impl<'a, 'b> RefUnwindSafe for QrCodeBuilder<'a, 'b>
impl<'a, 'b> Send for QrCodeBuilder<'a, 'b>
impl<'a, 'b> Sync for QrCodeBuilder<'a, 'b>
impl<'a, 'b> Unpin for QrCodeBuilder<'a, 'b>
impl<'a, 'b> UnwindSafe for QrCodeBuilder<'a, 'b>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more