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

The encoded QR code symbol.

Implementations

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 qrcode::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.

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 qrcode::{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.

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

use qrcode::{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 qrcode::{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.

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 qrcode::{QrCode, Version, EcLevel};
use qrcode::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.

Gets the version of this QR code.

Gets the error correction level of this QR code.

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.

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.

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

Converts the QR code into a human-readable string. This is mainly for debugging only.

👎 Deprecated since 0.4.0:

use to_colors() instead

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.

👎 Deprecated since 0.4.0:

use into_colors() instead

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.

Converts the QR code to a vector of colors.

Converts the QR code to a vector of colors.

Renders the QR code into an image. The result is an image builder, which you may do some additional configuration before copying it into a concrete image.

Examples

let image = QrCode::new(b"hello").unwrap()
                   .render()
                   .dark_color(Rgb([0, 0, 128]))
                   .light_color(Rgb([224, 224, 224])) // adjust colors
                   .quiet_zone(false)          // disable quiet zone (white border)
                   .min_dimensions(300, 300)   // sets minimum image size
                   .build();

Note: the image crate itself also provides method to rotate the image, or overlay a logo on top of the QR code.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

The returned type after indexing.

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

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

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more