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