[][src]Struct qrcode::QrCode

pub struct QrCode { /* fields omitted */ }

The encoded QR code symbol.

Methods

impl QrCode[src]

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

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();

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

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();

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

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();

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

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);

pub fn version(&self) -> Version[src]

Gets the version of this QR code.

pub fn error_correction_level(&self) -> EcLevel[src]

Gets the error correction level of this QR code.

pub fn width(&self) -> usize[src]

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.

pub fn max_allowed_errors(&self) -> usize[src]

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.

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

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

pub fn to_debug_str(&self, on_char: char, off_char: char) -> String[src]

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

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

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.

pub fn into_vec(self) -> Vec<bool>[src]

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.

pub fn to_colors(&self) -> Vec<Color>[src]

Converts the QR code to a vector of colors.

pub fn into_colors(self) -> Vec<Color>[src]

Converts the QR code to a vector of colors.

pub fn render<P: Pixel>(&self) -> Renderer<P>[src]

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 { data: [0, 0, 128] })
                    .light_color(Rgb { data: [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

impl Clone for QrCode[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Index<(usize, usize)> for QrCode[src]

type Output = Color

The returned type after indexing.

Auto Trait Implementations

impl Send for QrCode

impl Unpin for QrCode

impl Sync for QrCode

impl UnwindSafe for QrCode

impl RefUnwindSafe for QrCode

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]