1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Provides a simple and safe API.

use crate::builder::*;
use crate::ec::ECLevel;
use crate::mask::Mask;
use crate::matrix::Matrix;
use crate::mode::Mode;
use crate::version::Version;

/// The QR code.
///
/// Encapsulates a matrix, the 2D-grid containing the QR modules
/// and some information about the QR code.
#[derive(Debug, PartialEq, Eq)]
pub struct Qr {
    /// Version of the QR code.
    pub version: Version,

    /// Error correction level.
    pub ecl: ECLevel,

    /// Encoding mode.
    pub mode: Mode,

    /// The modules.
    pub matrix: Matrix,

    /// The applied mask, 0 to 7.
    pub mask: Mask,
}

impl Qr {
    /// Create a new QR from a string.
    pub fn new(s: &str) -> Result<Qr, Error> {
        QrBuilder::new()
            .version(Version::new(3))
            .ecl(ECLevel::L)
            .into(s)
    }

    /// Returns the size of the QR code.
    pub fn size(&self) -> usize {
        self.version.size()
    }
}