Skip to content

Commit c7780e8

Browse files
authored
Merge pull request #81 from sorairolake/add-docs
docs: Add missing documentation
2 parents 72aea62 + 81cc58a commit c7780e8

File tree

7 files changed

+31
-0
lines changed

7 files changed

+31
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#![cfg_attr(not(feature = "std"), no_std)]
2929
#![cfg_attr(feature = "bench", feature(test))] // Unstable libraries
3030
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
31+
#![warn(missing_docs)]
3132
#![warn(clippy::pedantic)]
3233
#![allow(
3334
clippy::must_use_candidate, // This is just annoying.

src/optimize.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ mod parse_tests {
252252
//------------------------------------------------------------------------------
253253
//{{{ Optimizer
254254

255+
/// QR code data optimizer.
255256
pub struct Optimizer<I> {
256257
parser: I,
257258
last_segment: Segment,
@@ -287,6 +288,7 @@ impl<I: Iterator<Item = Segment>> Optimizer<I> {
287288
}
288289

289290
impl Parser<'_> {
291+
/// Creates a new `Optimizer` based on this parser.
290292
pub fn optimize(self, version: Version) -> Optimizer<Self> {
291293
Optimizer::new(self, version)
292294
}

src/render/image.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Raster image rendering support powered by the [`image`] crate.
2+
13
#![cfg(feature = "image")]
24

35
use crate::render::{Canvas, Pixel};

src/render/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ pub trait Pixel: Copy + Sized {
3434

3535
/// Rendering canvas of a QR code image.
3636
pub trait Canvas: Sized {
37+
/// Type of an image pixel.
3738
type Pixel: Sized;
39+
40+
/// Type of the finalized image.
3841
type Image: Sized;
3942

4043
/// Constructs a new canvas of the given dimensions.
@@ -43,6 +46,8 @@ pub trait Canvas: Sized {
4346
/// Draws a single dark pixel at the (x, y) coordinate.
4447
fn draw_dark_pixel(&mut self, x: u32, y: u32);
4548

49+
/// Draws a dark rectangle with dimensions `width`×`height` at the (`left`,
50+
/// `top`) coordinate.
4651
fn draw_dark_rect(&mut self, left: u32, top: u32, width: u32, height: u32) {
4752
for y in top..(top + height) {
4853
for x in left..(left + width) {
@@ -121,6 +126,14 @@ impl<'a, P: Pixel> Renderer<'a, P> {
121126
self
122127
}
123128

129+
/// Sets the minimum total image width (and thus height) in pixels,
130+
/// including the quiet zone if applicable. The renderer will try to find
131+
/// the dimension as small as possible, such that each module in the QR code
132+
/// has uniform size (no distortion).
133+
///
134+
/// For instance, a version 1 QR code has 19 modules across including the
135+
/// quiet zone. If we request an image of width ≥200px, we get that each
136+
/// module's size should be 11px, so the actual image size will be 209px.
124137
#[deprecated(since = "0.4.0", note = "use `.min_dimensions(width, width)` instead")]
125138
pub fn min_width(&mut self, width: u32) -> &mut Self {
126139
self.min_dimensions(width, width)

src/render/string.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ use alloc::string::String;
88
use alloc::vec;
99
use alloc::vec::Vec;
1010

11+
/// Abstraction of an image element.
1112
pub trait Element: Copy {
13+
/// Obtains the default element color when a module is dark or light.
1214
fn default_color(color: Color) -> Self;
15+
16+
/// Returns the number of bytes in `self`.
1317
fn strlen(self) -> usize;
18+
19+
/// Appends `self` to the end of the given `string`.
1420
fn append_to_string(self, string: &mut String);
1521
}
1622

src/render/unicode.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ use alloc::vec::Vec;
88

99
const CODEPAGE: [&str; 4] = [" ", "\u{2584}", "\u{2580}", "\u{2588}"];
1010

11+
/// An image pixel for UTF-8 rendering.
1112
#[derive(Copy, Clone, PartialEq, Eq)]
1213
pub enum Dense1x2 {
14+
/// The pixel is dark colored.
1315
Dark,
16+
/// The pixel is light colored.
1417
Light,
1518
}
1619

@@ -37,6 +40,7 @@ impl Dense1x2 {
3740
}
3841
}
3942

43+
/// A canvas for UTF-8 rendering with a resolution of 1×2 modules per character.
4044
pub struct Canvas1x2 {
4145
canvas: Vec<u8>,
4246
width: u32,

src/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! The `types` module contains types associated with the functional elements of
2+
//! a QR code.
3+
14
use crate::cast::As;
25
use core::cmp::{Ordering, PartialOrd};
36
use core::default::Default;

0 commit comments

Comments
 (0)