### SVG Rendering Example Source: https://docs.rs/qrcode/latest/qrcode/render/svg/index.html This example demonstrates how to generate an SVG representation of a QR code. ```APIDOC ## SVG Rendering Example ### Description This example demonstrates how to generate an SVG representation of a QR code using the `qrcode` crate. ### Method N/A (This is a code example, not an API endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) N/A (This is a code example, not an API endpoint) #### Response Example ```xml ... ``` ### Code ```rust use qrcode::QrCode; use qrcode::render::svg; let code = QrCode::new(b"Hello").unwrap(); let svg_xml = code.render::().build(); println!("{}", svg_xml); ``` ``` -------------------------------- ### PIC Rendering Example Source: https://docs.rs/qrcode/latest/qrcode/render/pic/index.html?search=std%3A%3Avec Demonstrates how to create a QR code and render it into the PIC format using the `qrcode` crate. ```APIDOC ## Module pic qrcode::render # Module pic Copy item path Source Expand description PIC rendering support. ## §Example ```rust use qrcode::QrCode; use qrcode::render::pic; let code = QrCode::new(b"Hello").unwrap(); let pic = code.render::().build(); println!("{}", pic); ``` ## Structs§ Color A PIC color. ``` -------------------------------- ### Canvas Module Usage Source: https://docs.rs/qrcode/latest/qrcode/canvas/index.html Example demonstrating how to create a Canvas, draw functional patterns, add data, apply a mask, and convert it to a boolean representation. ```APIDOC ## Module canvas ### Description The `canvas` module puts raw bits into the QR code canvas. ### Usage Example ```rust use qrcode::types::{Version, EcLevel}; use qrcode::canvas::{Canvas, MaskPattern}; let mut c = Canvas::new(Version::Normal(1), EcLevel::L); c.draw_all_functional_patterns(); c.draw_data(b"data_here", b"ec_code_here"); c.apply_mask(MaskPattern::Checkerboard); let bools = c.to_bools(); ``` ## Structs ### Canvas `Canvas` is an intermediate helper structure to render error-corrected data into a QR code. ## Enums ### MaskPattern The mask patterns. Since QR code and Micro QR code do not use the same pattern number, we name them according to their shape instead of the number. ### Module The color of a module (pixel) in the QR code. ## Functions ### is_functional Gets whether the module at the given coordinates represents a functional module. ``` -------------------------------- ### Initialize Bits Structure Source: https://docs.rs/qrcode/latest/qrcode/bits/struct.Bits.html Constructs a new, empty bits structure for a given QR code version. No setup or imports are required beyond this function. ```rust pub fn new(version: Version) -> Self ``` -------------------------------- ### Handle File Metadata Operations with Result Source: https://docs.rs/qrcode/latest/qrcode/types/type.QrResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates using `Result` for file system operations like getting metadata. It shows how to handle both successful and erroneous outcomes, such as a non-existent path. ```Rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### Result Methods Overview Source: https://docs.rs/qrcode/latest/qrcode/types/type.QrResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E This section provides an overview of common methods available on the Rust Result type, illustrating their usage with code examples. ```APIDOC ## Result Type Methods This documentation outlines various methods provided by Rust's `Result` enum for handling success and error conditions. ### `and_then` Chains fallible operations that may return `Err`. #### Method `and_then` #### Example ```rust fn sq_then_to_string(x: u32) -> Result { x.checked_mul(x).map(|sq| sq.to_string()).ok_or("overflowed") } assert_eq!(Ok(2).and_then(sq_then_to_string), Ok(4.to_string())); assert_eq!(Ok(1_000_000).and_then(sq_then_to_string), Err("overflowed")); assert_eq!(Err("not a number").and_then(sq_then_to_string), Err("not a number")); ``` ### `or` Returns `res` if the result is `Err`, otherwise returns the `Ok` value of `self`. #### Method `or` #### Parameters - **res** (Result) - The result to return if `self` is `Err`. #### Example ```rust let x: Result = Ok(2); let y: Result = Err("late error"); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("early error"); let y: Result = Ok(2); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("not a 2"); let y: Result = Err("late error"); assert_eq!(x.or(y), Err("late error")); let x: Result = Ok(2); let y: Result = Ok(100); assert_eq!(x.or(y), Ok(2)); ``` ### `or_else` Calls `op` if the result is `Err`, otherwise returns the `Ok` value of `self`. This function can be used for control flow based on result values. #### Method `or_else` #### Parameters - **op** (FnOnce(E) -> Result) - A closure that is called if `self` is `Err`. #### Example ```rust fn sq(x: u32) -> Result { Ok(x * x) } fn err(x: u32) -> Result { Err(x) } assert_eq!(Ok(2).or_else(sq).or_else(sq), Ok(2)); assert_eq!(Ok(2).or_else(err).or_else(sq), Ok(2)); assert_eq!(Err(3).or_else(sq).or_else(err), Ok(9)); assert_eq!(Err(3).or_else(err).or_else(err), Err(3)); ``` ### `unwrap_or` Returns the contained `Ok` value or a provided default. Arguments passed to `unwrap_or` are eagerly evaluated. #### Method `unwrap_or` #### Parameters - **default** (T) - The default value to return if `self` is `Err`. #### Example ```rust let default = 2; let x: Result = Ok(9); assert_eq!(x.unwrap_or(default), 9); let x: Result = Err("error"); assert_eq!(x.unwrap_or(default), default); ``` ### `unwrap_or_else` Returns the contained `Ok` value or computes it from a closure. #### Method `unwrap_or_else` #### Parameters - **op** (FnOnce(E) -> T) - A closure that computes the default value if `self` is `Err`. #### Example ```rust fn count(x: &str) -> usize { x.len() } assert_eq!(Ok(2).unwrap_or_else(count), 2); assert_eq!(Err("foo").unwrap_or_else(count), 3); ``` ### `unwrap_unchecked` Returns the contained `Ok` value without checking that the value is not an `Err`. **Safety**: Calling this method on an `Err` is undefined behavior. #### Method `unwrap_unchecked` #### Example ```rust let x: Result = Ok(2); assert_eq!(unsafe { x.unwrap_unchecked() }, 2); let x: Result = Err("emergency failure"); unsafe { x.unwrap_unchecked() }; // Undefined behavior! ``` ### `unwrap_err_unchecked` Returns the contained `Err` value without checking that the value is not an `Ok`. **Safety**: Calling this method on an `Ok` is undefined behavior. #### Method `unwrap_err_unchecked` #### Example ```rust let x: Result = Ok(2); unsafe { x.unwrap_err_unchecked() }; // Undefined behavior! let x: Result = Err("emergency failure"); assert_eq!(unsafe { x.unwrap_err_unchecked() }, "emergency failure"); ``` ``` -------------------------------- ### unwrap() - Get Ok value or panic Source: https://docs.rs/qrcode/latest/qrcode/types/type.QrResult.html?search=u32+-%3E+bool Retrieves the value from an Ok variant, panicking if the variant is Err. ```APIDOC ## GET /api/unwrap ### Description Retrieves the value from an Ok variant, panicking if the variant is Err. ### Method GET ### Endpoint /api/unwrap ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```json { "example": "No request body needed for this operation." } ``` ### Response #### Success Response (200) - **value** (T) - The contained Ok value. #### Error Response (Panic) - Panics if the result is an Err, with a panic message provided by the Err's value. #### Response Example ```json { "example": "2" } ``` ``` -------------------------------- ### QrCode Encoding and Rendering Source: https://docs.rs/qrcode/latest/qrcode/index.html?search= Demonstrates how to initialize a QrCode object with binary data and render it into an image or a string representation. ```APIDOC ## QrCode Encoding ### Description Encodes binary data into a QR code symbol and provides methods for rendering the output. ### Usage ```rust use qrcode::QrCode; use image::Luma; // Encode some data into bits. let code = QrCode::new(b"01234567").unwrap(); // Render the bits into an image. let image = code.render::>().build(); // Save the image. image.save("/tmp/qrcode.png").unwrap(); // You can also render it into a string. let string = code.render() .light_color(' ') .dark_color('#') .build(); println!("{}", string); ``` ``` -------------------------------- ### Module Access and Manipulation Source: https://docs.rs/qrcode/latest/qrcode/canvas/struct.Canvas.html?search=u32+-%3E+bool Methods for getting and setting individual modules on the canvas. ```APIDOC ### `get(&self, x: i16, y: i16) -> Module` Obtains a module at the given coordinates. For convenience, negative coordinates will wrap around. ### `get_mut(&mut self, x: i16, y: i16) -> &mut Module` Obtains a mutable module at the given coordinates. For convenience, negative coordinates will wrap around. ### `put(&mut self, x: i16, y: i16, color: Color)` Sets the color of a functional module at the given coordinates. For convenience, negative coordinates will wrap around. ``` -------------------------------- ### unwrap_err() - Get Err value Source: https://docs.rs/qrcode/latest/qrcode/types/type.QrResult.html?search=u32+-%3E+bool Retrieves the Err value, panicking if the variant is Ok. ```APIDOC ## GET /api/unwrap_err ### Description Retrieves the Err value, panicking if the variant is Ok. ### Method GET ### Endpoint /api/unwrap_err ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```json { "example": "No request body needed for this operation." } ``` ### Response #### Success Response (200) - **error_value** (E) - The contained Err value. #### Error Response (Panic) - Panics if the result is an Ok, with a custom panic message provided by the Ok's value. #### Response Example ```json { "example": "emergency failure" } ``` ``` -------------------------------- ### Render QR Code as PIC Source: https://docs.rs/qrcode/latest/qrcode/render/pic/index.html?search= Demonstrates how to generate a QR code and render it using the pic::Color renderer. ```APIDOC ## Render QR Code ### Description Generates a QR code from input bytes and renders it into a PIC format string. ### Request Example ```rust use qrcode::QrCode; use qrcode::render::pic; let code = QrCode::new(b"Hello").unwrap(); let pic = code.render::().build(); println!("{}", pic); ``` ``` -------------------------------- ### QrCode Constructor Methods Source: https://docs.rs/qrcode/latest/qrcode/struct.QrCode.html?search=std%3A%3Avec Methods for creating new QrCode instances with varying levels of configuration. ```APIDOC ## QrCode::new ### Description Constructs a new QR code which automatically encodes the given data using the medium error correction level and the smallest possible QR code version. ### Parameters - **data** (AsRef<[u8]>) - Required - The data to encode. ### Response - **QrResult** - Returns the constructed QrCode or an error if the data is too long. ## QrCode::with_error_correction_level ### Description Constructs a new QR code which automatically encodes the given data at a specific error correction level. ### Parameters - **data** (AsRef<[u8]>) - Required - The data to encode. - **ec_level** (EcLevel) - Required - The desired error correction level. ## QrCode::with_version ### Description Constructs a new QR code for the given version and error correction level. ### Parameters - **data** (AsRef<[u8]>) - Required - The data to encode. - **version** (Version) - Required - The specific QR code version. - **ec_level** (EcLevel) - Required - The desired error correction level. ``` -------------------------------- ### expect_err() - Get Err value or panic Source: https://docs.rs/qrcode/latest/qrcode/types/type.QrResult.html?search=u32+-%3E+bool Retrieves the Err value, panicking if the variant is Ok. ```APIDOC ## GET /api/expect_err ### Description Retrieves the Err value, panicking if the variant is Ok. Requires a custom panic message. ### Method GET ### Endpoint /api/expect_err ### Parameters #### Path Parameters - None #### Query Parameters - **msg** (string) - Required - The custom message to include in the panic if the result is Ok. #### Request Body - None ### Request Example ```json { "example": "No request body needed for this operation." } ``` ### Response #### Success Response (200) - **error_value** (E) - The contained Err value. #### Error Response (Panic) - Panics if the result is an Ok, with a panic message including the provided `msg` and the content of the Ok value. #### Response Example ```json { "example": "emergency failure" } ``` ``` -------------------------------- ### Get Type ID Source: https://docs.rs/qrcode/latest/qrcode/bits/struct.Bits.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the `TypeId` of the current instance. This is a standard method for trait objects. ```rust self.type_id() ``` -------------------------------- ### Rendering a QrCode Source: https://docs.rs/qrcode/latest/qrcode/struct.QrCode.html Demonstrates how to create a new QrCode instance and configure its visual properties such as colors, quiet zone, and dimensions before building the final image. ```APIDOC ## Rendering a QrCode ### Description Configures and builds a QR code image with custom styling. ### Request Example ```rust let image = QrCode::new(b"hello").unwrap() .render() .dark_color(Rgb([0, 0, 128])) .light_color(Rgb([224, 224, 224])) .quiet_zone(false) .min_dimensions(300, 300) .build(); ``` ``` -------------------------------- ### Create New QR Code Renderer Source: https://docs.rs/qrcode/latest/qrcode/render/struct.Renderer.html?search=std%3A%3Avec Initializes a new `Renderer` instance. Panics if the provided content length does not match the expected dimensions. ```rust pub fn new( content: &'a [Color], modules_count: usize, quiet_zone: u32, ) -> Renderer<'a, P> ``` -------------------------------- ### Get QR Code Version Source: https://docs.rs/qrcode/latest/qrcode/bits/struct.Bits.html Retrieves the QR code version associated with this bits structure. ```rust pub fn version(&self) -> Version ``` -------------------------------- ### Renderer::new Source: https://docs.rs/qrcode/latest/qrcode/render/struct.Renderer.html?search= Creates a new Renderer instance. ```APIDOC ## fn new(content: &'a [Color], modules_count: usize, quiet_zone: u32) -> Renderer<'a, P> ### Description Creates a new renderer. ### Parameters - **content** (*&[Color]*) - Required - A slice of Color representing the QR code data. - **modules_count** (*usize*) - Required - The number of modules (pixels) per side of the QR code. - **quiet_zone** (*u32*) - Required - The size of the quiet zone around the QR code. ### Panics Panics if the length of `content` is not exactly `modules_count * modules_count`. ``` -------------------------------- ### Push ECI designator Source: https://docs.rs/qrcode/latest/qrcode/bits/struct.Bits.html?search=std%3A%3Avec Example of pushing an ECI designator followed by byte data to the bits structure. ```rust #![allow(unused_must_use)] use qrcode::bits::Bits; use qrcode::types::Version; let mut bits = Bits::new(Version::Normal(1)); bits.push_eci_designator(9); // 9 = ISO-8859-7 (Greek). bits.push_byte_data(b"\xa1\xa2\xa3\xa4\xa5"); // ΑΒΓΔΕ ``` -------------------------------- ### Unwrap Ok Value Source: https://docs.rs/qrcode/latest/qrcode/types/type.QrResult.html?search= Use `unwrap()` to get the contained `Ok` value. Panics if the result is `Err`. ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` -------------------------------- ### Bits Initialization and Utility Methods Source: https://docs.rs/qrcode/latest/qrcode/bits/struct.Bits.html?search=u32+-%3E+bool Methods for creating a new Bits instance and checking its properties. ```APIDOC ## impl Bits ### pub fn new(version: Version) -> Self #### Description Constructs a new, empty bits structure. #### Parameters - **version** (Version) - The QR code version to initialize with. ### pub fn len(&self) -> usize #### Description Total number of bits currently pushed. ### pub fn is_empty(&self) -> bool #### Description Whether there are any bits pushed. ### pub fn version(&self) -> Version #### Description Returns the QR code version associated with this Bits instance. ### pub fn into_bytes(self) -> Vec #### Description Convert the bits into a bytes vector. ``` -------------------------------- ### Get Maximum Allowed Errors Source: https://docs.rs/qrcode/latest/qrcode/struct.QrCode.html?search=u32+-%3E+bool Retrieves the maximum number of modules that can be corrupted before the data becomes unreadable. ```rust let max_errors = code.max_allowed_errors(); ``` -------------------------------- ### Get QR Code Width Source: https://docs.rs/qrcode/latest/qrcode/struct.QrCode.html?search=u32+-%3E+bool Retrieves the width of the QR code in modules, excluding the quiet zone. ```rust let width = code.width(); ``` -------------------------------- ### Renderer Structure and Initialization Source: https://docs.rs/qrcode/latest/qrcode/render/struct.Renderer.html?search=u32+-%3E+bool Details on the Renderer struct and its constructor. ```APIDOC ## Struct Renderer ### Description A QR code renderer. This is a builder type which converts a bool-vector into an image. ### Constructor #### `new(content: &'a [Color], modules_count: usize, quiet_zone: u32) -> Renderer<'a, P>` Creates a new renderer. #### Panics Panics if the length of `content` is not exactly `modules_count * modules_count`. ``` -------------------------------- ### QrCode Constructors Source: https://docs.rs/qrcode/latest/qrcode/struct.QrCode.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods to instantiate a new QrCode object with varying levels of configuration. ```APIDOC ## QrCode::new ### Description Constructs a new QR code which automatically encodes the given data using the medium error correction level and the smallest possible QR code version. ### Parameters - **data** (AsRef<[u8]>) - Required - The data to encode. ### Response - **QrResult** - The constructed QrCode or an error if construction fails. ## QrCode::with_error_correction_level ### Description Constructs a new QR code which automatically encodes the given data at a specific error correction level. ### Parameters - **data** (AsRef<[u8]>) - Required - The data to encode. - **ec_level** (EcLevel) - Required - The desired error correction level. ## QrCode::with_version ### Description Constructs a new QR code for the given version and error correction level, supporting both standard and Micro QR codes. ### Parameters - **data** (AsRef<[u8]>) - Required - The data to encode. - **version** (Version) - Required - The specific QR code version. - **ec_level** (EcLevel) - Required - The desired error correction level. ``` -------------------------------- ### Get QR Code Error Correction Level Source: https://docs.rs/qrcode/latest/qrcode/struct.QrCode.html?search=u32+-%3E+bool Retrieves the error correction level of the QR code. ```rust let ec_level = code.error_correction_level(); ``` -------------------------------- ### Build QR Code Image Source: https://docs.rs/qrcode/latest/qrcode/render/struct.Renderer.html?search=std%3A%3Avec Renders the configured QR code into an image of type `P::Image`. ```rust pub fn build(&self) -> P::Image ``` -------------------------------- ### Get Type ID Source: https://docs.rs/qrcode/latest/qrcode/bits/struct.Bits.html?search= Retrieves the unique `TypeId` of the current instance. Useful for runtime type identification. ```rust self.type_id() ``` -------------------------------- ### Result Implementations for QrResult Source: https://docs.rs/qrcode/latest/qrcode/types/type.QrResult.html?search=std%3A%3Avec Provides documentation for various methods implemented on the Result type, applicable to QrResult. ```APIDOC ## Implementations ### impl Result<&T, E> #### pub const fn copied(self) -> Result Maps a `Result<&T, E>` to a `Result` by copying the contents of the `Ok` part. ##### §Examples ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` #### pub fn cloned(self) -> Result Maps a `Result<&T, E>` to a `Result` by cloning the contents of the `Ok` part. ##### §Examples ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ### impl Result<&mut T, E> #### pub const fn copied(self) -> Result Maps a `Result<&mut T, E>` to a `Result` by copying the contents of the `Ok` part. ##### §Examples ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` #### pub fn cloned(self) -> Result Maps a `Result<&mut T, E>` to a `Result` by cloning the contents of the `Ok` part. ##### §Examples ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ### impl Result, E> #### pub const fn transpose(self) -> Option> Transposes a `Result` of an `Option` into an `Option` of a `Result`. `Ok(None)` will be mapped to `None`. `Ok(Some(_))` and `Err(_)` will be mapped to `Some(Ok(_))` and `Some(Err(_))`. ##### §Examples ```rust #[derive(Debug, Eq, PartialEq)] struct SomeErr; let x: Result, SomeErr> = Ok(Some(5)); let y: Option> = Some(Ok(5)); assert_eq!(x.transpose(), y); ``` ### impl Result, E> #### pub const fn flatten(self) -> Result Converts from `Result, E>` to `Result`. ##### §Examples ```rust let x: Result, u32> = Ok(Ok("hello")); assert_eq!(Ok("hello"), x.flatten()); let x: Result, u32> = Ok(Err(6)); assert_eq!(Err(6), x.flatten()); let x: Result, u32> = Err(6); assert_eq!(Err(6), x.flatten()); ``` Flattening only removes one level of nesting at a time: ```rust let x: Result, u32>, u32> = Ok(Ok(Ok("hello"))); assert_eq!(Ok(Ok("hello")), x.flatten()); assert_eq!(Ok("hello"), x.flatten().flatten()); ``` ### impl Result #### pub const fn is_ok(&self) -> bool Returns `true` if the result is `Ok`. ##### §Examples ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` #### pub fn is_ok_and(self, f: F) -> bool where F: FnOnce(T) -> bool, Returns `true` if the result is `Ok` and the value inside of it matches a predicate. ##### §Examples ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` #### pub const fn is_err(&self) -> bool Returns `true` if the result is `Err`. ##### §Examples ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` #### pub fn is_err_and(self, f: F) -> bool where F: FnOnce(E) -> bool, Returns `true` if the result is `Err` and the value inside of it matches a predicate. ``` -------------------------------- ### Version Methods Source: https://docs.rs/qrcode/latest/qrcode/types/enum.Version.html?search= Available methods for the Version enum, including getting dimensions, fetching data, and checking version type. ```APIDOC ## impl Version ### Methods #### `pub fn width(self) -> i16` Get the number of “modules” on each side of the QR code, i.e. the width and height of the code. #### `pub fn fetch(self, ec_level: EcLevel, table: &[[T; 4]]) -> QrResult` Obtains an object from a hard-coded table. The table must be a 44×4 array. The outer array represents the content for each version. The first 40 entry corresponds to QR code versions 1 to 40, and the last 4 corresponds to Micro QR code version 1 to 4. The inner array represents the content in each error correction level, in the order [L, M, Q, H]. ##### Errors If the entry compares equal to the default value of `T`, this method returns `Err(QrError::InvalidVersion)`. #### `pub fn mode_bits_count(self) -> usize` The number of bits needed to encode the mode indicator. #### `pub fn is_micro(self) -> bool` Checks whether the version refers to a Micro QR code. ``` -------------------------------- ### Renderer Methods Source: https://docs.rs/qrcode/latest/qrcode/render/struct.Renderer.html?search=std%3A%3Avec Methods for configuring and building the QR code image. ```APIDOC ## Renderer Methods ### `dark_color(&mut self, color: P) -> &mut Self` Sets the color of a dark module. Default is opaque black. ### `light_color(&mut self, color: P) -> &mut Self` Sets the color of a light module. Default is opaque white. ### `quiet_zone(&mut self, has_quiet_zone: bool) -> &mut Self` Determines whether to include the quiet zone in the generated image. ### `module_size(&mut self, width: u32) -> &mut Self` *Deprecated since 0.4.0: use `.module_dimensions(width, width)` instead* Sets the size of each module in pixels. Default is 8px. ### `module_dimensions(&mut self, width: u32, height: u32) -> &mut Self` Sets the size of each module in pixels. Default is 8x8. ### `min_width(&mut self, width: u32) -> &mut Self` *Deprecated since 0.4.0: use `.min_dimensions(width, width)` instead* ### `min_dimensions(&mut self, width: u32, height: u32) -> &mut Self` Sets the minimum total image size in pixels, including the quiet zone if applicable. The renderer will try to find the smallest possible dimension such that each module has a uniform size. ### `max_dimensions(&mut self, width: u32, height: u32) -> &mut Self` Sets the maximum total image size in pixels, including the quiet zone if applicable. The renderer will try to find the largest possible dimension such that each module has a uniform size. ### `to_image(&self) -> P::Image` *Deprecated since 0.4.0: renamed to `.build()` to de-emphasize the image connection* Renders the QR code into an image. ### `build(&self) -> P::Image` Renders the QR code into an image. ``` -------------------------------- ### Push FNC1 first position indicator Source: https://docs.rs/qrcode/latest/qrcode/bits/struct.Bits.html?search=std%3A%3Avec Example of encoding an FNC1 first position indicator followed by numeric and alphanumeric data. ```rust #![allow(unused_must_use)] use qrcode::bits::Bits; use qrcode::types::Version; let mut bits = Bits::new(Version::Normal(1)); bits.push_fnc1_first_position(); bits.push_numeric_data(b"01049123451234591597033130128"); bits.push_alphanumeric_data(b"%10ABC123"); ``` -------------------------------- ### Render QR Code as SVG Source: https://docs.rs/qrcode/latest/qrcode/render/svg/index.html?search=std%3A%3Avec Demonstrates how to generate a QR code and render it into an SVG XML string using the svg::Color renderer. ```APIDOC ## Render QR Code as SVG ### Description Generates a QR code from input bytes and renders it into an SVG XML format using the `qrcode::render::svg` module. ### Request Example ```rust use qrcode::QrCode; use qrcode::render::svg; let code = QrCode::new(b"Hello").unwrap(); let svg_xml = code.render::().build(); println!("{}", svg_xml); ``` ### Response #### Success Response (200) - **svg_xml** (String) - The resulting SVG XML string representing the QR code. ``` -------------------------------- ### Get if module is functional Source: https://docs.rs/qrcode/latest/qrcode/canvas/fn.is_functional.html?search= Use this function to determine if the module at the specified coordinates is functional. It requires the version, width, and x, y coordinates. ```rust pub fn is_functional(version: Version, width: i16, x: i16, y: i16) -> bool ``` -------------------------------- ### into_ok() - Convert to Ok value (nightly) Source: https://docs.rs/qrcode/latest/qrcode/types/type.QrResult.html?search=u32+-%3E+bool Returns the contained Ok value, never panics. This is an experimental API. ```APIDOC ## GET /api/into_ok ### Description Returns the contained Ok value, never panics. This is an experimental API that is only available on nightly Rust. ### Method GET ### Endpoint /api/into_ok ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```json { "example": "No request body needed for this operation." } ``` ### Response #### Success Response (200) - **value** (T) - The contained Ok value. #### Response Example ```json { "example": "this is fine" } ``` ``` -------------------------------- ### Core API Components Source: https://docs.rs/qrcode/latest/qrcode/all.html Overview of the primary structs, enums, and functions available in the qrcode-0.14.1 crate. ```APIDOC ## Core Structs - **QrCode**: The primary structure for representing a QR code. - **canvas::Canvas**: Represents the grid of modules for a QR code. - **optimize::Optimizer**: Handles the optimization of data segments. ## Key Enums - **types::EcLevel**: Defines the error correction level (e.g., L, M, Q, H). - **types::Mode**: Specifies the encoding mode (e.g., Numeric, Alphanumeric, Byte). - **types::QrError**: Represents potential errors during QR code generation. ## Primary Functions - **bits::encode_auto**: Automatically encodes data into a QR code structure. - **ec::create_error_correction_code**: Generates error correction codewords for a given data set. ``` -------------------------------- ### Segment Struct Definition Source: https://docs.rs/qrcode/latest/qrcode/optimize/struct.Segment.html?search=u32+-%3E+bool The Segment struct represents a segment of data committed to a specific encoding mode, defined by its start and end indices. ```APIDOC ## Struct qrcode::optimize::Segment ### Description A segment of data committed to an encoding mode. ### Fields - **mode** (Mode) - The encoding mode of the segment of data. - **begin** (usize) - The start index of the segment. - **end** (usize) - The end index (exclusive) of the segment. ``` -------------------------------- ### Collect into Result with Checked Addition Source: https://docs.rs/qrcode/latest/qrcode/types/type.QrResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Use `collect()` to gather results from an iterator into a `Result`. This example demonstrates checked addition, returning an `Err` on overflow. ```rust let v = vec![1, 2]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_add(1).ok_or("Overflow!") ).collect(); assert_eq!(res, Ok(vec![2, 3])); ``` -------------------------------- ### QrCode Construction Methods Source: https://docs.rs/qrcode/latest/qrcode/struct.QrCode.html Methods for creating new QrCode instances with varying levels of control over data, error correction, and versioning. ```APIDOC ## QrCode::new ### Description Constructs a new QR code which automatically encodes the given data using the medium error correction level and the smallest possible QR code version. ### Parameters - **data** (AsRef<[u8]>) - Required - The data to encode. ### Response - **QrResult** - Returns the constructed QrCode or an error if the data is too long. ## QrCode::with_error_correction_level ### Description Constructs a new QR code which automatically encodes the given data at a specific error correction level. ### Parameters - **data** (AsRef<[u8]>) - Required - The data to encode. - **ec_level** (EcLevel) - Required - The desired error correction level. ## QrCode::with_version ### Description Constructs a new QR code for a specific version and error correction level. Supports standard and Micro QR codes. ### Parameters - **data** (AsRef<[u8]>) - Required - The data to encode. - **version** (Version) - Required - The specific QR code version. - **ec_level** (EcLevel) - Required - The desired error correction level. ``` -------------------------------- ### Render QR Code to Image (Deprecated) Source: https://docs.rs/qrcode/latest/qrcode/render/struct.Renderer.html?search=std%3A%3Avec Deprecated: Renamed to `.build()` to avoid emphasizing image-specific output. Renders the QR code into an image. ```rust pub fn to_image(&self) -> P::Image ``` -------------------------------- ### Termination Reporting Source: https://docs.rs/qrcode/latest/qrcode/types/type.QrResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E The `report` method is part of the `Termination` trait for `Result`. It is called to get the representation of the value as a status code, which is then returned to the operating system. ```APIDOC ## fn report(self) -> ExitCode ### Description Is called to get the representation of the value as status code. This status code is returned to the operating system. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Not applicable for this function" } ``` ### Response #### Success Response (200) - **report** (ExitCode) - The status code representation of the Result. #### Response Example ```json { "example": "ExitCode::SUCCESS" } ``` ``` -------------------------------- ### POST /render Source: https://docs.rs/qrcode/latest/qrcode/struct.QrCode.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Generates a customized QR code image from input data. ```APIDOC ## POST /render ### Description Generates a QR code image with custom styling options such as colors, quiet zones, and dimensions. ### Method POST ### Endpoint /render ### Parameters #### Request Body - **data** (bytes) - Required - The content to encode into the QR code. - **dark_color** (Rgb) - Optional - The color used for the dark modules of the QR code. - **light_color** (Rgb) - Optional - The color used for the light modules of the QR code. - **quiet_zone** (bool) - Optional - Whether to include a white border around the QR code. - **min_dimensions** (tuple) - Optional - The minimum width and height of the generated image. ### Request Example { "data": "hello", "dark_color": [0, 0, 128], "light_color": [224, 224, 224], "quiet_zone": false, "min_dimensions": [300, 300] } ``` -------------------------------- ### Iterate Mutably Over Ok Value Source: https://docs.rs/qrcode/latest/qrcode/types/type.QrResult.html?search=std%3A%3Avec Use `iter_mut` to get a mutable iterator over the contained value if the Result is `Ok`. This allows modifying the value in place. ```rust let mut x: Result = Ok(7); match x.iter_mut().next() { Some(v) => *v = 40, None => {}, } assert_eq!(x, Ok(40)); let mut x: Result = Err("nothing!"); assert_eq!(x.iter_mut().next(), None); ``` -------------------------------- ### Renderer Configuration Methods Source: https://docs.rs/qrcode/latest/qrcode/render/struct.Renderer.html?search=u32+-%3E+bool Methods to configure the appearance and dimensions of the rendered QR code. ```APIDOC ## Renderer Configuration ### `dark_color(color: P) -> &mut Self` Sets the color of a dark module. Default is opaque black. ### `light_color(color: P) -> &mut Self` Sets the color of a light module. Default is opaque white. ### `quiet_zone(has_quiet_zone: bool) -> &mut Self` Determines whether to include the quiet zone in the generated image. ### `module_size(width: u32) -> &mut Self` Deprecated since 0.4.0: use `.module_dimensions(width, width)` instead. Sets the size of each module in pixels. Default is 8px. ### `module_dimensions(width: u32, height: u32) -> &mut Self` Sets the size of each module in pixels. Default is 8x8. ### `min_width(width: u32) -> &mut Self` Deprecated since 0.4.0: use `.min_dimensions(width, width)` instead. ### `min_dimensions(width: u32, height: u32) -> &mut Self` Sets the minimum total image size in pixels, including the quiet zone if applicable. The renderer will try to find the dimension as small as possible, such that each module in the QR code has uniform size (no distortion). ### `max_dimensions(width: u32, height: u32) -> &mut Self` Sets the maximum total image size in pixels, including the quiet zone if applicable. The renderer will try to find the dimension as large as possible, such that each module in the QR code has uniform size (no distortion). ``` -------------------------------- ### Version Methods Source: https://docs.rs/qrcode/latest/qrcode/types/enum.Version.html?search=std%3A%3Avec Methods available for the Version enum, including getting the width, fetching data from tables, and checking if it's a Micro QR code. ```APIDOC ## impl Version ### pub fn width(self) -> i16 Get the number of “modules” on each side of the QR code, i.e. the width and height of the code. ### pub fn fetch(self, ec_level: EcLevel, table: &[[T; 4]]) -> QrResult where T: PartialEq + Default + Copy, Obtains an object from a hard-coded table. The table must be a 44×4 array. The outer array represents the content for each version. The first 40 entry corresponds to QR code versions 1 to 40, and the last 4 corresponds to Micro QR code version 1 to 4. The inner array represents the content in each error correction level, in the order [L, M, Q, H]. #### Errors If the entry compares equal to the default value of `T`, this method returns `Err(QrError::InvalidVersion)`. ### pub fn mode_bits_count(self) -> usize The number of bits needed to encode the mode indicator. ### pub fn is_micro(self) -> bool Checks whether the version refers to a Micro QR code. ``` -------------------------------- ### QR Code Rendering Overview Source: https://docs.rs/qrcode/latest/qrcode/render/index.html This section provides an overview of the QR code rendering module and its supported formats. ```APIDOC ## QR Code Rendering ### Description Render a QR code into image. ### Supported Rendering Formats - **image**: General image rendering. - **pic**: PIC rendering support. - **string**: String rendering support. - **svg**: SVG rendering support. - **unicode**: UTF-8 rendering, with 2 pixels per symbol. ### Core Components #### Structs - **Renderer** A QR code renderer. This is a builder type which converts a bool-vector into an image. #### Traits - **Canvas** Rendering canvas of a QR code image. - **Pixel** Abstraction of an image pixel. ``` -------------------------------- ### Get Current Bit Length Source: https://docs.rs/qrcode/latest/qrcode/bits/struct.Bits.html Returns the total number of bits currently stored in the structure. Useful for tracking progress or estimating remaining capacity. ```rust pub fn len(&self) -> usize ``` -------------------------------- ### Renderer Configuration Methods Source: https://docs.rs/qrcode/latest/qrcode/render/struct.Renderer.html?search= Methods to configure the appearance and dimensions of the rendered QR code. ```APIDOC ## Renderer Configuration ### `dark_color(color: P) -> &mut Self` Sets the color for dark modules. Defaults to opaque black. ### `light_color(color: P) -> &mut Self` Sets the color for light modules. Defaults to opaque white. ### `quiet_zone(has_quiet_zone: bool) -> &mut Self` Specifies whether to include the quiet zone in the generated image. ### `module_size(width: u32) -> &mut Self` *Deprecated since 0.4.0: use `.module_dimensions(width, width)` instead* Sets the size of each module in pixels. Defaults to 8px. ### `module_dimensions(width: u32, height: u32) -> &mut Self` Sets the dimensions (width and height) of each module in pixels. Defaults to 8x8. ### `min_width(width: u32) -> &mut Self` *Deprecated since 0.4.0: use `.min_dimensions(width, width)` instead* Sets the minimum width of the total image in pixels. ### `min_dimensions(width: u32, height: u32) -> &mut Self` Sets the minimum total image size in pixels, including the quiet zone if applicable. The renderer attempts to find the smallest possible dimension while maintaining uniform module size. ### `max_dimensions(width: u32, height: u32) -> &mut Self` Sets the maximum total image size in pixels, including the quiet zone if applicable. The renderer attempts to find the largest possible dimension while maintaining uniform module size. ``` -------------------------------- ### Create and use a new Parser Source: https://docs.rs/qrcode/latest/qrcode/optimize/struct.Parser.html?search=u32+-%3E+bool Initializes a new parser to segment input data and collects the results into a vector. ```rust use qrcode::optimize::{Parser, Segment}; use qrcode::types::Mode::{Alphanumeric, Numeric, Byte}; let parse_res = Parser::new(b"ABC123abcd").collect::>(); assert_eq!(parse_res, vec![Segment { mode: Alphanumeric, begin: 0, end: 3 }, Segment { mode: Numeric, begin: 3, end: 6 }, Segment { mode: Byte, begin: 6, end: 10 }]); ``` -------------------------------- ### Get References to Result Values with `as_ref()` Source: https://docs.rs/qrcode/latest/qrcode/types/type.QrResult.html?search= Use `as_ref()` to convert a `&Result` into a `Result<&T, &E>`. This allows you to inspect the values within a `Result` without taking ownership or modifying it. ```rust let x: Result = Ok(2); assert_eq!(x.as_ref(), Ok(&2)); let x: Result = Err("Error"); assert_eq!(x.as_ref(), Err(&"Error")); ``` -------------------------------- ### Canvas Module Usage Source: https://docs.rs/qrcode/latest/qrcode/canvas/index.html?search=u32+-%3E+bool Demonstrates how to use the `Canvas` struct to create, draw data onto, and mask a QR code, then convert it to a boolean representation. ```APIDOC ## Module canvas The `canvas` module puts raw bits into the QR code canvas. ### Usage Example ```rust use qrcode::types::{Version, EcLevel}; use qrcode::canvas::{Canvas, MaskPattern}; let mut c = Canvas::new(Version::Normal(1), EcLevel::L); c.draw_all_functional_patterns(); c.draw_data(b"data_here", b"ec_code_here"); c.apply_mask(MaskPattern::Checkerboard); let bools = c.to_bools(); ``` ### Structs #### Canvas `Canvas` is an intermediate helper structure to render error-corrected data into a QR code. ### Enums #### MaskPattern The mask patterns. Since QR code and Micro QR code do not use the same pattern number, we name them according to their shape instead of the number. #### Module The color of a module (pixel) in the QR code. ### Functions #### is_functional Gets whether the module at the given coordinates represents a functional module. ```