Skip to main content

QrCode

Struct QrCode 

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

A finished QR symbol: a square grid of dark and light modules.

Implementations§

Source§

impl QrCode

Source

pub fn size(&self) -> usize

Side length in modules, 4 * version + 17.

Source

pub fn version(&self) -> u8

The symbol version, 1 to 10.

Source

pub fn ecc(&self) -> Ecc

The error-correction level the symbol was built at.

Source

pub fn mask(&self) -> u8

Which of the eight data masks the penalty rules selected. Recorded in the format information, so a reader does not have to guess.

Source

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

Whether the module at (x, y) is dark. Out-of-range coordinates read as light, which is what the quiet zone is anyway.

Source§

impl QrCode

Source

pub fn to_svg_default(&self) -> String

Render as a standalone <svg> element, four pixels per module and a four-module quiet zone. The common case for an enrolment page.

Source

pub fn to_svg(&self, module_pixels: u32, quiet_zone: u32) -> String

Render as a standalone <svg> element with a default title.

module_pixels is the on-screen size of one module and quiet_zone the margin around the symbol, in modules. The standard asks for at least four, and readers really do need it — a QR code butted up against surrounding content often will not scan.

Source

pub fn to_svg_titled( &self, module_pixels: u32, quiet_zone: u32, title: &str, ) -> String

Render as a standalone <svg> element with a caller-supplied title.

The output deliberately contains no <style> element, no style attribute and no script: it is embedded in a page served under style-src 'self'; script-src 'self' with no unsafe-inline, so anything inline would simply be dropped by the browser and the code would render as a blank square. Colours are presentation attributes, which CSP does not police.

All of the dark modules go into one <path>, accumulated as horizontal runs. A version 10 symbol has 3249 modules, and one element each would be a document large enough to notice on every page load.

Trait Implementations§

Source§

impl Clone for QrCode

Source§

fn clone(&self) -> QrCode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.