Struct qr_code::QrCode

source ·
pub struct QrCode { /* private fields */ }
Expand description

The encoded QR code symbol.

Implementations§

source§

impl QrCode

source

pub fn to_string(&self, inverted: bool, border: u8) -> String

Render the qr code in a utf-8 string (2x1 pixel per character) inverted toggle the foreground and background color

source

pub fn to_bmp(&self) -> Bmp

Available on crate feature bmp only.

Convert the QRCode to Bmp

source§

impl QrCode

source

pub fn new<D: AsRef<[u8]>>(data: D) -> QrResult<Self>

Constructs a new QR code which automatically encodes the given data.

This method uses the “medium” error correction level and automatically chooses the smallest QR code.

use qr_code::QrCode;

let code = QrCode::new(b"Some data").unwrap();
Errors

Returns error if the QR code cannot be constructed, e.g. when the data is too long.

source

pub fn with_error_correction_level<D: AsRef<[u8]>>( data: D, ec_level: EcLevel ) -> QrResult<Self>

Constructs a new QR code which automatically encodes the given data at a specific error correction level.

This method automatically chooses the smallest QR code.

use qr_code::{QrCode, EcLevel};

let code = QrCode::with_error_correction_level(b"Some data", EcLevel::H).unwrap();
Errors

Returns error if the QR code cannot be constructed, e.g. when the data is too long.

source

pub fn with_version<D: AsRef<[u8]>>( data: D, version: Version, ec_level: EcLevel ) -> QrResult<Self>

Constructs a new QR code for the given version and error correction level.

use qr_code::{QrCode, Version, EcLevel};

let code = QrCode::with_version(b"Some data", Version::Normal(5), EcLevel::M).unwrap();

This method can also be used to generate Micro QR code.

use qr_code::{QrCode, Version, EcLevel};

let micro_code = QrCode::with_version(b"123", Version::Micro(1), EcLevel::L).unwrap();
Errors

Returns error if the QR code cannot be constructed, e.g. when the data is too long, or when the version and error correction level are incompatible.

source

pub fn with_bits(bits: Bits, ec_level: EcLevel) -> QrResult<Self>

Constructs a new QR code with encoded bits.

Use this method only if there are very special need to manipulate the raw bits before encoding. Some examples are:

  • Encode data using specific character set with ECI
  • Use the FNC1 modes
  • Avoid the optimal segmentation algorithm

See the Bits structure for detail.

#![allow(unused_must_use)]

use qr_code::{QrCode, Version, EcLevel};
use qr_code::bits::Bits;

let mut bits = Bits::new(Version::Normal(1));
bits.push_eci_designator(9);
bits.push_byte_data(b"\xca\xfe\xe4\xe9\xea\xe1\xf2 QR");
bits.push_terminator(EcLevel::L);
let qrcode = QrCode::with_bits(bits, EcLevel::L);
Errors

Returns error if the QR code cannot be constructed, e.g. when the bits are too long, or when the version and error correction level are incompatible.

source

pub fn version(&self) -> Version

Gets the version of this QR code.

source

pub fn error_correction_level(&self) -> EcLevel

Gets the error correction level of this QR code.

source

pub fn width(&self) -> usize

Gets the number of modules per side, i.e. the width of this QR code.

The width here does not contain the quiet zone paddings.

source

pub fn max_allowed_errors(&self) -> usize

Gets the maximum number of allowed erratic modules can be introduced before the data becomes corrupted. Note that errors should not be introduced to functional modules.

source

pub fn is_functional(&self, x: usize, y: usize) -> bool

Checks whether a module at coordinate (x, y) is a functional module or not.

source

pub fn to_vec(&self) -> Vec<bool>

Converts the QR code to a vector of booleans. Each entry represents the color of the module, with “true” means dark and “false” means light.

source

pub fn iter(&self) -> QrCodeIterator<'_>

Returns an iterator over QR code vector of colors.

source

pub fn into_colors(self) -> Vec<Color>

Converts the QR code to a vector of colors.

Trait Implementations§

source§

impl Clone for QrCode

source§

fn clone(&self) -> QrCode

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for QrCode

source§

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

Formats the value using the given formatter. Read more
source§

impl Index<(usize, usize)> for QrCode

§

type Output = Color

The returned type after indexing.
source§

fn index(&self, (x, y): (usize, usize)) -> &Color

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.