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
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
impl QRCode
Implementation of QRCode structure.
sourcepub fn new(data: Vec<u8>) -> QRCode
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
: AVec<u8>
representing the data to be encoded in the QR code.
Returns
A new QRCode
instance.
sourcepub fn from_string(data: String) -> QRCode
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
sourcepub fn from_bytes(data: Vec<u8>) -> QRCode
pub fn from_bytes(data: Vec<u8>) -> QRCode
Creates a new QRCode structure from a vector of bytes.
sourcepub fn to_png(&self, width: u32) -> ImageBuffer<Rgba<u8>, Vec<u8>>
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.
sourcepub fn to_jpg(&self, width: u32) -> ImageBuffer<Rgba<u8>, Vec<u8>>
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.
sourcepub fn to_gif(&self, width: u32) -> ImageBuffer<Rgba<u8>, Vec<u8>>
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.
sourcepub fn to_svg(&self, width: u32) -> String
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.
sourcepub fn colorize(&self, color: Rgba<u8>) -> ImageBuffer<Rgba<u8>, Vec<u8>>
pub fn colorize(&self, color: Rgba<u8>) -> ImageBuffer<Rgba<u8>, Vec<u8>>
Colorizes the QR code with the specified color.
Parameters
color
: TheRgba<u8>
color value to use for the QR code.
Returns
A colorized RgbaImage
of the QR code.
sourcepub fn resize(&self, width: u32, height: u32) -> ImageBuffer<Rgba<u8>, Vec<u8>>
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.
sourcepub fn add_image_watermark(
img: &mut ImageBuffer<Rgba<u8>, Vec<u8>>,
watermark: &ImageBuffer<Rgba<u8>, Vec<u8>>
)
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 theRgbaImage
of the QR code.watermark
: A reference to the watermarkRgbaImage
.
sourcepub fn create_multilanguage(data_map: HashMap<String, String>) -> QRCode
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
: AHashMap
mapping language codes (String
) to data (String
).
Returns
A QRCode
instance representing a multilingual QR code.
sourcepub fn create_dynamic(initial_data: &str) -> QRCode
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.
sourcepub fn combine_qr_codes(codes: Vec<QRCode>) -> Result<QRCode, &'static str>
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 ofQRCode
instances to combine.
Returns
A Result
which is either a combined QRCode
instance or an error string.
sourcepub fn compress_data(data: &str) -> Vec<u8> ⓘ
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.
sourcepub fn batch_generate_qr_codes(data: Vec<String>) -> Vec<QRCode>
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.
sourcepub fn overlay_image(
&self,
overlay: &ImageBuffer<Rgba<u8>, Vec<u8>>
) -> ImageBuffer<Rgba<u8>, Vec<u8>>
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 theRgbaImage
to overlay on the QR code.
Returns
A combined RgbaImage
with the overlay applied.
sourcepub fn set_encoding_format(&self, format: &str) -> Result<QRCode, &'static str>
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.
sourcepub fn get_encoding_format(&self) -> &str
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 Ord for QRCode
impl Ord for QRCode
source§impl PartialEq for QRCode
impl PartialEq for QRCode
source§impl PartialOrd for QRCode
impl PartialOrd for QRCode
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for QRCode
impl StructuralEq for QRCode
impl StructuralPartialEq for QRCode
Auto Trait Implementations§
impl RefUnwindSafe for QRCode
impl Send for QRCode
impl Sync for QRCode
impl Unpin for QRCode
impl UnwindSafe for QRCode
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.