Struct mini_functions::qr::QRCode

source ·
#[non_exhaustive]
pub struct QRCode { pub data: Vec<u8>, /* private fields */ }
Expand description

Re-exported main qrc module from qrc for QR code generation. Represents a QR code containing data.

This struct can be used to generate QR code images in various formats. It supports encoding data as a QR code and rendering it in formats like PNG, JPG, and SVG.

Examples

use qrc::QRCode;

// Create a new QR code with text data
let qr = QRCode::new("Hello, world!".as_bytes().to_vec());

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§data: Vec<u8>

The data field holds the data to be encoded in the QR code.

Implementations§

source§

impl QRCode

Implementation of QRCode structure.

source

pub fn new(data: Vec<u8>) -> QRCode

Creates a new QRCode instance with the given data.

Examples
use qrc::QRCode;

let qr = QRCode::new("Hello, world!".as_bytes().to_vec());
Parameters
  • data: A Vec<u8> representing the data to be encoded in the QR code.
Returns

A new QRCode instance.

source

pub fn from_string(data: String) -> QRCode

The from_string method creates a new instance of the QRCode struct by converting the given string data into a vector of bytes

source

pub fn from_bytes(data: Vec<u8>) -> QRCode

Creates a new QRCode structure from a vector of bytes.

source

pub fn to_qrcode(&self) -> QrCode

Converts the QRCode structure to a QrCode structure.

source

pub fn to_png(&self, width: u32) -> ImageBuffer<Rgba<u8>, Vec<u8>>

Converts the QRCode structure to a PNG image.

Examples
use qrc::QRCode;

// Convert a string slice to a String using `.to_string()`
let qr = QRCode::from_string("Hello, world!".to_string());
let png_image = qr.to_png(256);
Parameters
  • width: The width of the image in pixels.
Returns

An ImageBuffer representing the QR code in PNG format.

source

pub fn to_jpg(&self, width: u32) -> ImageBuffer<Rgba<u8>, Vec<u8>>

Converts the QRCode structure to a JPG image.

Parameters
  • width: The width of the desired image in pixels.
Returns

An ImageBuffer representing the QR code in JPG format.

source

pub fn to_gif(&self, width: u32) -> ImageBuffer<Rgba<u8>, Vec<u8>>

Converts the QRCode structure to a GIF image.

Parameters
  • width: The width of the desired image in pixels.
Returns

An ImageBuffer representing the QR code in GIF format.

source

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

Converts the QRCode structure to an SVG image.

Parameters
  • width: The width of the desired image in pixels.
Returns

A String representing the QR code in SVG format.

source

pub fn colorize(&self, color: Rgba<u8>) -> ImageBuffer<Rgba<u8>, Vec<u8>>

Colorizes the QR code with the specified color.

Parameters
  • color: The Rgba<u8> color value to use for the QR code.
Returns

A colorized RgbaImage of the QR code.

source

pub fn resize(&self, width: u32, height: u32) -> ImageBuffer<Rgba<u8>, Vec<u8>>

Resizes the QR code image to the specified width and height.

Parameters
  • width: The width of the image in pixels.
  • height: The height of the image in pixels.
Returns

A resized RgbaImage of the QR code.

source

pub fn add_image_watermark( img: &mut ImageBuffer<Rgba<u8>, Vec<u8>>, watermark: &ImageBuffer<Rgba<u8>, Vec<u8>> )

Adds a watermark image to the QR code.

Parameters
  • img: A mutable reference to the RgbaImage of the QR code.
  • watermark: A reference to the watermark RgbaImage.
source

pub fn create_multilanguage(data_map: HashMap<String, String>) -> QRCode

Creates a multilingual QR code based on a map of language codes to data strings.

Parameters
  • data_map: A HashMap mapping language codes (String) to data (String).
Returns

A QRCode instance representing a multilingual QR code.

source

pub fn create_dynamic(initial_data: &str) -> QRCode

Generates a dynamic QR code that can be updated after creation.

Parameters
  • initial_data: A string slice representing the initial data for the QR code.
Returns

A QRCode instance representing a dynamic QR code.

source

pub fn combine_qr_codes(codes: Vec<QRCode>) -> Result<QRCode, &'static str>

Combines multiple QR codes into a single larger QR code.

Parameters
  • codes: A vector of QRCode instances to combine.
Returns

A Result which is either a combined QRCode instance or an error string.

source

pub fn compress_data(data: &str) -> Vec<u8>

Compresses the provided data string using Zlib compression.

Parameters
  • data: A string slice representing the data to compress.
Returns

A Vec<u8> containing the compressed data.

source

pub fn batch_generate_qr_codes(data: Vec<String>) -> Vec<QRCode>

Generates a batch of QR codes from a vector of data strings.

Parameters
  • data: A vector of strings, each representing data for a separate QR code.
Returns

A vector of QRCode instances.

source

pub fn overlay_image( &self, overlay: &ImageBuffer<Rgba<u8>, Vec<u8>> ) -> ImageBuffer<Rgba<u8>, Vec<u8>>

Overlays an image on top of the QR code.

Parameters
  • overlay: A reference to the RgbaImage to overlay on the QR code.
Returns

A combined RgbaImage with the overlay applied.

source

pub fn set_encoding_format(&self, format: &str) -> Result<QRCode, &'static str>

Sets the encoding format of the QR code.

Parameters
  • format: A string slice representing the encoding format.
Returns

A Result which is either a new QRCode instance with updated encoding or an error string.

source

pub fn get_encoding_format(&self) -> &str

Retrieves the encoding format of the QR code.

Returns

A string slice representing the encoding format.

Trait Implementations§

source§

impl Clone for QRCode

source§

fn clone(&self) -> QRCode

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 QRCode

source§

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

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

impl Default for QRCode

source§

fn default() -> QRCode

Returns the “default value” for a type. Read more
source§

impl Hash for QRCode

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for QRCode

source§

fn cmp(&self, other: &QRCode) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for QRCode

source§

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

source§

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

This method returns an ordering between self and other values if one exists. Read more
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 Eq for QRCode

source§

impl StructuralEq for QRCode

source§

impl StructuralPartialEq for QRCode

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T> Same for T

§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V