[][src]Struct qrcodegen::QrCode

pub struct QrCode { /* fields omitted */ }

A QR Code symbol, which is a type of two-dimension barcode.

Invented by Denso Wave and described in the ISO/IEC 18004 standard.

Instances of this struct represent an immutable square grid of black and white cells. The impl provides static factory functions to create a QR Code from text or binary data. The struct and impl cover the QR Code Model 2 specification, supporting all versions (sizes) from 1 to 40, all 4 error correction levels, and 4 character encoding modes.

Ways to create a QR Code object:

  • High level: Take the payload data and call QrCode::encode_text() or QrCode::encode_binary().
  • Mid level: Custom-make the list of segments and call QrCode::encode_segments() or QrCode::encode_segments_advanced().
  • Low level: Custom-make the array of data codeword bytes (including segment headers and final padding, excluding error correction codewords), supply the appropriate version number, and call the QrCode::encode_codewords() constructor.

(Note that all ways require supplying the desired error correction level.)

Methods

impl QrCode[src]

pub fn encode_text(text: &str, ecl: QrCodeEcc) -> Result<Self, DataTooLong>[src]

Returns a QR Code representing the given Unicode text string at the given error correction level.

As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer Unicode code points (not UTF-8 code units) if the low error correction level is used. The smallest possible QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.

Returns a wrapped QrCode if successful, or Err if the data is too long to fit in any version at the given ECC level.

pub fn encode_binary(data: &[u8], ecl: QrCodeEcc) -> Result<Self, DataTooLong>[src]

Returns a QR Code representing the given binary data at the given error correction level.

This function always encodes using the binary segment mode, not any text mode. The maximum number of bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.

Returns a wrapped QrCode if successful, or Err if the data is too long to fit in any version at the given ECC level.

pub fn encode_segments(
    segs: &[QrSegment],
    ecl: QrCodeEcc
) -> Result<Self, DataTooLong>
[src]

Returns a QR Code representing the given segments at the given error correction level.

The smallest possible QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.

This function allows the user to create a custom sequence of segments that switches between modes (such as alphanumeric and byte) to encode text in less space. This is a mid-level API; the high-level API is encode_text() and encode_binary().

Returns a wrapped QrCode if successful, or Err if the data is too long to fit in any version at the given ECC level.

pub fn encode_segments_advanced(
    segs: &[QrSegment],
    ecl: QrCodeEcc,
    minversion: Version,
    maxversion: Version,
    mask: Option<Mask>,
    boostecl: bool
) -> Result<Self, DataTooLong>
[src]

Returns a QR Code representing the given segments with the given encoding parameters.

The smallest possible QR Code version within the given range is automatically chosen for the output. Iff boostecl is true, then the ECC level of the result may be higher than the ecl argument if it can be done without increasing the version. The mask number is either between 0 to 7 (inclusive) to force that mask, or None to automatically choose an appropriate mask (which may be slow).

This function allows the user to create a custom sequence of segments that switches between modes (such as alphanumeric and byte) to encode text in less space. This is a mid-level API; the high-level API is encode_text() and encode_binary().

Returns a wrapped QrCode if successful, or Err if the data is too long to fit in any version in the given range at the given ECC level.

pub fn encode_codewords(
    ver: Version,
    ecl: QrCodeEcc,
    datacodewords: &[u8],
    mask: Option<Mask>
) -> Self
[src]

Creates a new QR Code with the given version number, error correction level, data codeword bytes, and mask number.

This is a low-level API that most users should not use directly. A mid-level API is the encode_segments() function.

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

Returns this QR Code's version, in the range [1, 40].

pub fn size(&self) -> i32[src]

Returns this QR Code's size, in the range [21, 177].

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

Returns this QR Code's error correction level.

pub fn mask(&self) -> Mask[src]

Returns this QR Code's mask, in the range [0, 7].

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

Returns the color of the module (pixel) at the given coordinates, which is false for white or true for black.

The top left corner has the coordinates (x=0, y=0). If the given coordinates are out of bounds, then false (white) is returned.

pub fn to_svg_string(&self, border: i32) -> String[src]

Returns a string of SVG code for an image depicting this QR Code, with the given number of border modules.

The string always uses Unix newlines (\n), regardless of the platform.

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

Auto Trait Implementations

impl Unpin for QrCode

impl Sync for QrCode

impl Send for QrCode

impl RefUnwindSafe for QrCode

impl UnwindSafe for QrCode

Blanket Implementations

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

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

type Owned = T

The resulting type after obtaining ownership.

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> Borrow<T> for T where
    T: ?Sized
[src]

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

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