Struct matrix_qrcode::qrcode::QrCode
[−]pub struct QrCode { /* private fields */ }
Expand description
The encoded QR code symbol.
Implementations
impl QrCode
impl QrCode
pub fn new<D>(data: D) -> Result<QrCode, QrError> where
D: AsRef<[u8]>,
pub fn new<D>(data: D) -> Result<QrCode, QrError> where
D: AsRef<[u8]>,
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.
pub fn with_error_correction_level<D>(
data: D,
ec_level: EcLevel
) -> Result<QrCode, QrError> where
D: AsRef<[u8]>,
pub fn with_error_correction_level<D>(
data: D,
ec_level: EcLevel
) -> Result<QrCode, QrError> where
D: AsRef<[u8]>,
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.
pub fn with_version<D>(
data: D,
version: Version,
ec_level: EcLevel
) -> Result<QrCode, QrError> where
D: AsRef<[u8]>,
pub fn with_version<D>(
data: D,
version: Version,
ec_level: EcLevel
) -> Result<QrCode, QrError> where
D: AsRef<[u8]>,
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.
pub fn with_bits(bits: Bits, ec_level: EcLevel) -> Result<QrCode, QrError>
pub fn with_bits(bits: Bits, ec_level: EcLevel) -> Result<QrCode, QrError>
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.
pub fn error_correction_level(&self) -> EcLevel
pub fn error_correction_level(&self) -> EcLevel
Gets the error correction level of this QR code.
pub fn width(&self) -> usize
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.
pub fn max_allowed_errors(&self) -> usize
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.
pub fn is_functional(&self, x: usize, y: usize) -> bool
pub fn is_functional(&self, x: usize, y: usize) -> bool
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
pub fn to_debug_str(&self, on_char: char, off_char: char) -> String
Converts the QR code into a human-readable string. This is mainly for debugging only.
pub fn to_vec(&self) -> Vec<bool, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
👎 Deprecated since 0.4.0: use to_colors()
instead
pub fn to_vec(&self) -> Vec<bool, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
👎 Deprecated since 0.4.0: use into_colors()
instead
pub fn into_vec(self) -> Vec<bool, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn to_colors(&self) -> Vec<Color, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Converts the QR code to a vector of colors.
pub fn into_colors(self) -> Vec<Color, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn into_colors(self) -> Vec<Color, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Converts the QR code to a vector of colors.
pub fn render<P>(&self) -> Renderer<'_, P> where
P: Pixel,
pub fn render<P>(&self) -> Renderer<'_, P> where
P: Pixel,
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
Auto Trait Implementations
impl RefUnwindSafe for QrCode
impl Send for QrCode
impl Sync for QrCode
impl Unpin for QrCode
impl UnwindSafe for QrCode
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more