Struct QrCodeBuilder

Source
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 between SIZE_MIN and SIZE_MAX (their values might change in future releases).

Note that these are only checked in QrCodeBuilder::build.

§Defaults

  • bg_color and logo_bg_color default to white.
  • size defaults to DEFAULT_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>

Source

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.

Source

pub fn with_size(&mut self, size: u32) -> &mut Self

Sets the dimensions of the QR Code to size x size.

Source

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.

Source

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.

Source

pub fn build(&self) -> Result<Vec<u8>, Error>

Constructs the QR Code.

The argument requirements are applied here, hence the Result return type.

Trait Implementations§

Source§

impl<'a, 'b> Debug for QrCodeBuilder<'a, 'b>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.