pub struct QrSegment { /* private fields */ }
Expand description

A segment of character/binary/control data in a QR Code symbol.

Instances of this struct are immutable.

The mid-level way to create a segment is to take the payload data and call a static factory function such as QrSegment::make_numeric(). The low-level way to create a segment is to custom-make the bit buffer and call the QrSegment::new() constructor with appropriate values.

This segment struct imposes no length restrictions, but QR Codes have restrictions. Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. Any segment longer than this is meaningless for the purpose of generating QR Codes.

Implementations§

source§

impl QrSegment

source

pub fn make_bytes(data: &[u8]) -> QrSegment

Returns a segment representing the given binary data encoded in byte mode.

All input byte slices are acceptable.

Any text string can be converted to UTF-8 bytes and encoded as a byte mode segment.

source

pub fn make_numeric(text: &str) -> QrSegment

Returns a segment representing the given string of decimal digits encoded in numeric mode.

Panics if the string contains non-digit characters.

source

pub fn make_alphanumeric(text: &str) -> QrSegment

Returns a segment representing the given text string encoded in alphanumeric mode.

The characters allowed are: 0 to 9, A to Z (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.

Panics if the string contains non-encodable characters.

source

pub fn make_segments(text: &str) -> Vec<QrSegment, Global>

Returns a list of zero or more segments to represent the given Unicode text string.

The result may use various segment modes and switch modes to optimize the length of the bit stream.

source

pub fn make_eci(assignval: u32) -> QrSegment

Returns a segment representing an Extended Channel Interpretation (ECI) designator with the given assignment value.

source

pub fn new( mode: QrSegmentMode, numchars: usize, data: Vec<bool, Global> ) -> QrSegment

Creates a new QR Code segment with the given attributes and data.

The character count (numchars) must agree with the mode and the bit buffer length, but the constraint isn’t checked.

source

pub fn mode(&self) -> QrSegmentMode

Returns the mode indicator of this segment.

source

pub fn num_chars(&self) -> usize

Returns the character count field of this segment.

source

pub fn data(&self) -> &Vec<bool, Global>

Returns the data bits of this segment.

source

pub fn is_numeric(text: &str) -> bool

Tests whether the given string can be encoded as a segment in numeric mode.

A string is encodable iff each character is in the range 0 to 9.

source

pub fn is_alphanumeric(text: &str) -> bool

Tests whether the given string can be encoded as a segment in alphanumeric mode.

A string is encodable iff each character is in the following set: 0 to 9, A to Z (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.

Trait Implementations§

source§

impl Clone for QrSegment

source§

fn clone(&self) -> QrSegment

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 PartialEq<QrSegment> for QrSegment

source§

fn eq(&self, other: &QrSegment) -> 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 Eq for QrSegment

source§

impl StructuralEq for QrSegment

source§

impl StructuralPartialEq for QrSegment

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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.