Debian Codegraph @

src/types.rs

raw symbols SCIP
1 use craterust-analyzer cargo qrcode 0.14.1 crate/::castrust-analyzer cargo qrcode 0.14.1 cast/::Asrust-analyzer cargo qrcode 0.14.1 cast/As#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::{Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#};
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/::Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#};
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Notrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Not#;
6
7 //------------------------------------------------------------------------------
8 //{{{ QrResult
9
10 /// `QrError` encodes the error encountered when generating a QR code.
11 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
12 pub enum QrErrorrust-analyzer cargo qrcode 0.14.1 types/QrError# {
13 /// The data is too long to encode into a QR code for the given version.
14 DataTooLongrust-analyzer cargo qrcode 0.14.1 types/QrError#DataTooLong#,
15
16 /// The provided version / error correction level combination is invalid.
17 InvalidVersionrust-analyzer cargo qrcode 0.14.1 types/QrError#InvalidVersion#,
18
19 /// Some characters in the data cannot be supported by the provided QR code
20 /// version.
21 UnsupportedCharacterSetrust-analyzer cargo qrcode 0.14.1 types/QrError#UnsupportedCharacterSet#,
22
23 /// The provided ECI designator is invalid. A valid designator should be
24 /// between 0 and 999999.
25 InvalidEciDesignatorrust-analyzer cargo qrcode 0.14.1 types/QrError#InvalidEciDesignator#,
26
27 /// A character not belonging to the character set is found.
28 InvalidCharacterrust-analyzer cargo qrcode 0.14.1 types/QrError#InvalidCharacter#,
29 }
30
31 impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for QrErrorrust-analyzer cargo qrcode 0.14.1 types/QrError# {
32 fn fmtrust-analyzer cargo qrcode 0.14.1 types/impl#[QrError][Display]fmt().(&self, fmt: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#> {
33 let msg = match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self {
34 QrErrorrust-analyzer cargo qrcode 0.14.1 types/QrError#::DataTooLongrust-analyzer cargo qrcode 0.14.1 types/QrError#DataTooLong# => "data too long",
35 QrErrorrust-analyzer cargo qrcode 0.14.1 types/QrError#::InvalidVersionrust-analyzer cargo qrcode 0.14.1 types/QrError#InvalidVersion# => "invalid version",
36 QrErrorrust-analyzer cargo qrcode 0.14.1 types/QrError#::UnsupportedCharacterSetrust-analyzer cargo qrcode 0.14.1 types/QrError#UnsupportedCharacterSet# => "unsupported character set",
37 QrErrorrust-analyzer cargo qrcode 0.14.1 types/QrError#::InvalidEciDesignatorrust-analyzer cargo qrcode 0.14.1 types/QrError#InvalidEciDesignator# => "invalid ECI designator",
38 QrErrorrust-analyzer cargo qrcode 0.14.1 types/QrError#::InvalidCharacterrust-analyzer cargo qrcode 0.14.1 types/QrError#InvalidCharacter# => "invalid character",
39 };
40 fmt.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(msg)
41 }
42 }
43
44 impl ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for QrErrorrust-analyzer cargo qrcode 0.14.1 types/QrError# {}
45
46 /// `QrResult` is a convenient alias for a QR code generation result.
47 pub type QrResultrust-analyzer cargo qrcode 0.14.1 types/QrResult#<T> = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, QrErrorrust-analyzer cargo qrcode 0.14.1 types/QrError#>;
48
49 //}}}
50 //------------------------------------------------------------------------------
51 //{{{ Color
52
53 /// The color of a module.
54 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
55 pub enum Colorrust-analyzer cargo qrcode 0.14.1 types/Color# {
56 /// The module is light colored.
57 Lightrust-analyzer cargo qrcode 0.14.1 types/Color#Light#,
58 /// The module is dark colored.
59 Darkrust-analyzer cargo qrcode 0.14.1 types/Color#Dark#,
60 }
61
62 impl Colorrust-analyzer cargo qrcode 0.14.1 types/Color# {
63 /// Selects a value according to color of the module. Equivalent to
64 /// `if self != Color::Light { dark } else { light }`.
65 ///
66 /// # Examples
67 ///
68 /// ```rust
69 /// # use qrcode::types::Color;
70 /// assert_eq!(Color::Light.select(1, 0), 0);
71 /// assert_eq!(Color::Dark.select("black", "white"), "black");
72 /// ```
73 pub fn selectrust-analyzer cargo qrcode 0.14.1 types/impl#[Color]select().<T>(self, dark: T, light: T) -> T {
74 match self {
75 Colorrust-analyzer cargo qrcode 0.14.1 types/Color#::Lightrust-analyzer cargo qrcode 0.14.1 types/Color#Light# => light,
76 Colorrust-analyzer cargo qrcode 0.14.1 types/Color#::Darkrust-analyzer cargo qrcode 0.14.1 types/Color#Dark# => dark,
77 }
78 }
79 }
80
81 impl Notrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/Not# for Colorrust-analyzer cargo qrcode 0.14.1 types/Color# {
82 type Outputrust-analyzer cargo qrcode 0.14.1 types/impl#[Color][Not]Output# = Selfrust-analyzer cargo qrcode 0.14.1 types/impl#[Color][Not];
83 fn notrust-analyzer cargo qrcode 0.14.1 types/impl#[Color][Not]not().(self) -> Selfrust-analyzer cargo qrcode 0.14.1 types/impl#[Color][Not] {
84 match self {
85 Colorrust-analyzer cargo qrcode 0.14.1 types/Color#::Lightrust-analyzer cargo qrcode 0.14.1 types/Color#Light# => Colorrust-analyzer cargo qrcode 0.14.1 types/Color#::Darkrust-analyzer cargo qrcode 0.14.1 types/Color#Dark#,
86 Colorrust-analyzer cargo qrcode 0.14.1 types/Color#::Darkrust-analyzer cargo qrcode 0.14.1 types/Color#Dark# => Colorrust-analyzer cargo qrcode 0.14.1 types/Color#::Lightrust-analyzer cargo qrcode 0.14.1 types/Color#Light#,
87 }
88 }
89 }
90
91 //}}}
92 //------------------------------------------------------------------------------
93 //{{{ Error correction level
94
95 /// The error correction level. It allows the original information be recovered
96 /// even if parts of the code is damaged.
97 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)]
98 pub enum EcLevelrust-analyzer cargo qrcode 0.14.1 types/EcLevel# {
99 /// Low error correction. Allows up to 7% of wrong blocks.
100 Lrust-analyzer cargo qrcode 0.14.1 types/EcLevel#L# = 0,
101
102 /// Medium error correction (default). Allows up to 15% of wrong blocks.
103 Mrust-analyzer cargo qrcode 0.14.1 types/EcLevel#M# = 1,
104
105 /// "Quartile" error correction. Allows up to 25% of wrong blocks.
106 Qrust-analyzer cargo qrcode 0.14.1 types/EcLevel#Q# = 2,
107
108 /// High error correction. Allows up to 30% of wrong blocks.
109 Hrust-analyzer cargo qrcode 0.14.1 types/EcLevel#H# = 3,
110 }
111
112 //}}}
113 //------------------------------------------------------------------------------
114 //{{{ Version
115
116 /// In QR code terminology, `Version` means the size of the generated image.
117 /// Larger version means the size of code is larger, and therefore can carry
118 /// more information.
119 ///
120 /// The smallest version is `Version::Normal(1)` of size 21×21, and the largest
121 /// is `Version::Normal(40)` of size 177×177.
122 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
123 pub enum Versionrust-analyzer cargo qrcode 0.14.1 types/Version# {
124 /// A normal QR code version. The parameter should be between 1 and 40.
125 Normalrust-analyzer cargo qrcode 0.14.1 types/Version#Normal#(i16),
126
127 /// A Micro QR code version. The parameter should be between 1 and 4.
128 Microrust-analyzer cargo qrcode 0.14.1 types/Version#Micro#(i16),
129 }
130
131 impl Versionrust-analyzer cargo qrcode 0.14.1 types/Version# {
132 /// Get the number of "modules" on each size of the QR code, i.e. the width
133 /// and height of the code.
134 pub fn widthrust-analyzer cargo qrcode 0.14.1 types/impl#[Version]width().(self) -> i16 {
135 match self {
136 Versionrust-analyzer cargo qrcode 0.14.1 types/Version#::Normalrust-analyzer cargo qrcode 0.14.1 types/Version#Normal#(v) => v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Mul<Self>`]mul().4 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().17,
137 Versionrust-analyzer cargo qrcode 0.14.1 types/Version#::Microrust-analyzer cargo qrcode 0.14.1 types/Version#Micro#(v) => v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Mul<Self>`]mul().2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().9,
138 }
139 }
140
141 /// Obtains an object from a hard-coded table.
142 ///
143 /// The table must be a 44×4 array. The outer array represents the content
144 /// for each version. The first 40 entry corresponds to QR code versions 1
145 /// to 40, and the last 4 corresponds to Micro QR code version 1 to 4. The
146 /// inner array represents the content in each error correction level, in
147 /// the order [L, M, Q, H].
148 ///
149 /// # Errors
150 ///
151 /// If the entry compares equal to the default value of `T`, this method
152 /// returns `Err(QrError::InvalidVersion)`.
153 pub fn fetchrust-analyzer cargo qrcode 0.14.1 types/impl#[Version]fetch().<T>(self, ec_level: EcLevelrust-analyzer cargo qrcode 0.14.1 types/EcLevel#, table: &[[T; 4]]) -> QrResultrust-analyzer cargo qrcode 0.14.1 types/QrResult#<T>
154 where
155 T: PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# + Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#,
156 {
157 match self {
158 Versionrust-analyzer cargo qrcode 0.14.1 types/Version#::Normalrust-analyzer cargo qrcode 0.14.1 types/Version#Normal#(v @ 1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#40) => {
159 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(table[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().(v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().1).as_usizerust-analyzer cargo qrcode 0.14.1 cast/impl#[i16][As]as_usize().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().ec_level as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().);
160 }
161 Versionrust-analyzer cargo qrcode 0.14.1 types/Version#::Microrust-analyzer cargo qrcode 0.14.1 types/Version#Micro#(v @ 1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#4) => {
162 let obj = table[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().(v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().39).as_usizerust-analyzer cargo qrcode 0.14.1 cast/impl#[i16][As]as_usize().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().ec_level as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().;
163 if obj rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().T::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().() {
164 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(obj);
165 }
166 }
167 _ => {}
168 }
169 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(QrErrorrust-analyzer cargo qrcode 0.14.1 types/QrError#::InvalidVersionrust-analyzer cargo qrcode 0.14.1 types/QrError#InvalidVersion#)
170 }
171
172 /// The number of bits needed to encode the mode indicator.
173 pub fn mode_bits_countrust-analyzer cargo qrcode 0.14.1 types/impl#[Version]mode_bits_count().(self) -> usize {
174 if let Versionrust-analyzer cargo qrcode 0.14.1 types/Version#::Microrust-analyzer cargo qrcode 0.14.1 types/Version#Micro#(a) = self {
175 (a rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().1).as_usizerust-analyzer cargo qrcode 0.14.1 cast/impl#[i16][As]as_usize().()
176 } else {
177 4
178 }
179 }
180
181 /// Checks whether is version refers to a Micro QR code.
182 pub fn is_microrust-analyzer cargo qrcode 0.14.1 types/impl#[Version]is_micro().(self) -> bool {
183 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, Versionrust-analyzer cargo qrcode 0.14.1 types/Version#::Microrust-analyzer cargo qrcode 0.14.1 types/Version#Micro#(_))
184 }
185 }
186
187 //}}}
188 //------------------------------------------------------------------------------
189 //{{{ Mode indicator
190
191 /// The mode indicator, which specifies the character set of the encoded data.
192 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
193 pub enum Moderust-analyzer cargo qrcode 0.14.1 types/Mode# {
194 /// The data contains only characters 0 to 9.
195 Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric#,
196
197 /// The data contains only uppercase letters (A–Z), numbers (0–9) and a few
198 /// punctuations marks (space, `$`, `%`, `*`, `+`, `-`, `.`, `/`, `:`).
199 Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric#,
200
201 /// The data contains arbitrary binary data.
202 Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte#,
203
204 /// The data contains Shift-JIS-encoded double-byte text.
205 Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji#,
206 }
207
208 impl Moderust-analyzer cargo qrcode 0.14.1 types/Mode# {
209 /// Computes the number of bits needed to encode the data length.
210 ///
211 /// use qrcode::types::{Version, Mode};
212 ///
213 /// assert_eq!(Mode::Numeric.length_bits_count(Version::Normal(1)), 10);
214 ///
215 /// This method will return `Err(QrError::UnsupportedCharacterSet)` if the
216 /// mode is not supported in the given version.
217 pub fn length_bits_countrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode]length_bits_count().(self, version: Versionrust-analyzer cargo qrcode 0.14.1 types/Version#) -> usize {
218 match version {
219 Versionrust-analyzer cargo qrcode 0.14.1 types/Version#::Microrust-analyzer cargo qrcode 0.14.1 types/Version#Micro#(a) => {
220 let a = a.as_usizerust-analyzer cargo qrcode 0.14.1 cast/impl#[i16][As]as_usize().();
221 match self {
222 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric# => 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().a,
223 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric# | Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte# => 1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().a,
224 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji# => a,
225 }
226 }
227 Versionrust-analyzer cargo qrcode 0.14.1 types/Version#::Normalrust-analyzer cargo qrcode 0.14.1 types/Version#Normal#(1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#9) => match self {
228 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric# => 10,
229 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric# => 9,
230 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte# | Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji# => 8,
231 },
232 Versionrust-analyzer cargo qrcode 0.14.1 types/Version#::Normalrust-analyzer cargo qrcode 0.14.1 types/Version#Normal#(10..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#26) => match self {
233 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric# => 12,
234 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric# => 11,
235 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte# => 16,
236 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji# => 10,
237 },
238 Versionrust-analyzer cargo qrcode 0.14.1 types/Version#::Normalrust-analyzer cargo qrcode 0.14.1 types/Version#Normal#(_) => match self {
239 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric# => 14,
240 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric# => 13,
241 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte# => 16,
242 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji# => 12,
243 },
244 }
245 }
246
247 /// Computes the number of bits needed to some data of a given raw length.
248 ///
249 /// use qrcode::types::Mode;
250 ///
251 /// assert_eq!(Mode::Numeric.data_bits_count(7), 24);
252 ///
253 /// Note that in Kanji mode, the `raw_data_len` is the number of Kanjis,
254 /// i.e. half the total size of bytes.
255 pub fn data_bits_countrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode]data_bits_count().(self, raw_data_len: usize) -> usize {
256 match self {
257 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric# => (raw_data_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().10 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().3,
258 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric# => (raw_data_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().11 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().2,
259 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte# => raw_data_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().8,
260 Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji# => raw_data_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().13,
261 }
262 }
263
264 /// Find the lowest common mode which both modes are compatible with.
265 ///
266 /// use qrcode::types::Mode;
267 ///
268 /// let a = Mode::Numeric;
269 /// let b = Mode::Kanji;
270 /// let c = a.max(b);
271 /// assert!(a <= c);
272 /// assert!(b <= c);
273 ///
274 #[must_use]
275 pub fn maxrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode]max().(self, other: Selfrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode]) -> Selfrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode] {
276 match self.partial_cmprust-analyzer cargo qrcode 0.14.1 types/impl#[Mode][`PartialOrd<Self>`]partial_cmp().(&other) {
277 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#) => self,
278 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => other,
279 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte#,
280 }
281 }
282 }
283
284 impl PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd# for Moderust-analyzer cargo qrcode 0.14.1 types/Mode# {
285 /// Defines a partial ordering between modes. If `a <= b`, then `b` contains
286 /// a superset of all characters supported by `a`.
287 fn partial_cmprust-analyzer cargo qrcode 0.14.1 types/impl#[Mode][`PartialOrd<Self>`]partial_cmp().(&self, other: &Selfrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode][`PartialOrd<Self>`]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
288 match (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().other) {
289 (a, b) if a rust-analyzer cargo qrcode 0.14.1 types/impl#[Mode][`PartialEq<Self>`]eq().==rust-analyzer cargo qrcode 0.14.1 types/impl#[Mode][`PartialEq<Self>`]eq(). rust-analyzer cargo qrcode 0.14.1 types/impl#[Mode][`PartialEq<Self>`]eq().b => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal#),
290 (Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric#, Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric#) | (_, Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte#) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#),
291 (Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric#, Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric#) | (Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte#, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#),
292 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
293 }
294 }
295 }
296
297 #[cfg(test)]
298 mod mode_testsrust-analyzer cargo qrcode 0.14.1 types/mode_tests/ {
299 use craterust-analyzer cargo qrcode 0.14.1 crate/::typesrust-analyzer cargo qrcode 0.14.1 types/::Moderust-analyzer cargo qrcode 0.14.1 types/Mode#::{Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric#, Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte#, Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji#, Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric#};
300
301 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
302 fn test_mode_orderrust-analyzer cargo qrcode 0.14.1 types/mode_tests/test_mode_order().() {
303 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric# <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt(). Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric#);
304 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte# >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt(). Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji#);
305 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric# <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt(). Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji#));
306 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric# >= Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji#));
307 }
308
309 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
310 fn test_maxrust-analyzer cargo qrcode 0.14.1 types/mode_tests/test_max().() {
311 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte#.maxrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode]max().(Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji#), Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte#);
312 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric#.maxrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode]max().(Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric#), Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric#);
313 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric#.maxrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode]max().(Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric#), Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric#);
314 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric#.maxrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode]max().(Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji#), Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte#);
315 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji#.maxrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode]max().(Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric#), Byterust-analyzer cargo qrcode 0.14.1 types/Mode#Byte#);
316 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric#.maxrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode]max().(Numericrust-analyzer cargo qrcode 0.14.1 types/Mode#Numeric#), Alphanumericrust-analyzer cargo qrcode 0.14.1 types/Mode#Alphanumeric#);
317 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji#.maxrust-analyzer cargo qrcode 0.14.1 types/impl#[Mode]max().(Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji#), Kanjirust-analyzer cargo qrcode 0.14.1 types/Mode#Kanji#);
318 }
319 }
320
321 //}}}