diff options
| author | Tobias Wiese <tobias@tobiaswiese.com> | 2026-01-26 03:11:14 +0100 |
|---|---|---|
| committer | Tobias Wiese <tobias@tobiaswiese.com> | 2026-01-27 00:25:43 +0100 |
| commit | 45d7335d8e18410728a0384fd6456c609aec3be8 (patch) | |
| tree | bf69699b326a69f17cbe8b61344b237c3b830a49 /examples | |
Initial commitv0.1.0
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/dmtx_text.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/dmtx_text.rs b/examples/dmtx_text.rs new file mode 100644 index 0000000..a8a4687 --- /dev/null +++ b/examples/dmtx_text.rs @@ -0,0 +1,31 @@ +use iec16022::DataMatrix; +use std::env::args_os; +use std::os::unix::ffi::OsStringExt; + +fn main() { + let data = args_os() + .skip(1) // program name + .map(|arg| arg.into_vec()) + .collect::<Vec<_>>() + .join(&b' '); + let dmtx = DataMatrix::encode(&data).unwrap(); + + let capacity = (dmtx.width() + 1) * dmtx.height(); + let mut out = String::with_capacity(capacity); + for row in (0..dmtx.height()).rev() { + for col in 0..dmtx.width() { + if dmtx.get(row, col) { + out.push('*'); + } else { + out.push(' '); + } + } + out.push('\n'); + } + debug_assert!( + capacity == out.capacity(), + "caculated capacity is not correct" + ); + + print!("{}", out); +} |
