Enum qrcode::types::Mode

source ·
pub enum Mode {
    Numeric,
    Alphanumeric,
    Byte,
    Kanji,
}
Expand description

The mode indicator, which specifies the character set of the encoded data.

Variants§

§

Numeric

The data contains only characters 0 to 9.

§

Alphanumeric

The data contains only uppercase letters (A–Z), numbers (0–9) and a few punctuations marks (space, $, %, *, +, -, ., /, :).

§

Byte

The data contains arbitrary binary data.

§

Kanji

The data contains Shift-JIS-encoded double-byte text.

Implementations§

source§

impl Mode

source

pub fn length_bits_count(self, version: Version) -> usize

Computes the number of bits needed to encode the data length.

use qrcode::types::{Version, Mode};

assert_eq!(Mode::Numeric.length_bits_count(Version::Normal(1)), 10);

This method will return Err(QrError::UnsupportedCharacterSet) if the mode is not supported in the given version.

source

pub fn data_bits_count(self, raw_data_len: usize) -> usize

Computes the number of bits needed to some data of a given raw length.

use qrcode::types::Mode;

assert_eq!(Mode::Numeric.data_bits_count(7), 24);

Note that in Kanji mode, the raw_data_len is the number of Kanjis, i.e. half the total size of bytes.

source

pub fn max(self, other: Self) -> Self

Find the lowest common mode which both modes are compatible with.

use qrcode::types::Mode;

let a = Mode::Numeric;
let b = Mode::Kanji;
let c = a.max(b);
assert!(a <= c);
assert!(b <= c);

Trait Implementations§

source§

impl Clone for Mode

source§

fn clone(&self) -> Mode

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Mode

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for Mode

source§

fn eq(&self, other: &Mode) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Mode

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

Defines a partial ordering between modes. If a <= b, then b contains a superset of all characters supported by a.

1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for Mode

source§

impl Eq for Mode

source§

impl StructuralPartialEq for Mode

Auto Trait Implementations§

§

impl Freeze for Mode

§

impl RefUnwindSafe for Mode

§

impl Send for Mode

§

impl Sync for Mode

§

impl Unpin for Mode

§

impl UnwindSafe for Mode

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> 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> ToOwned for T
where T: Clone,

§

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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.