Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tinytable"
version = "0.1.1"
version = "0.1.2"
edition = "2024"
rust-version = "1.85.0"
license = "Apache-2.0 OR MIT"
Expand Down
21 changes: 12 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![forbid(unsafe_code)]
#![warn(clippy::pedantic)]
#![allow(clippy::items_after_statements)]
#![allow(clippy::uninlined_format_args)]

//! A tiny text table drawing library.
//!
Expand All @@ -18,8 +19,8 @@
//! See [`write_table`] for examples and usage details.

use std::fmt::Display;
use std::fmt::Write as FmtWrite;
use std::io::{self, BufWriter, Write};
use std::iter;
use std::num::NonZeroUsize;

use unicode_segmentation::UnicodeSegmentation;
Expand Down Expand Up @@ -173,17 +174,19 @@ pub fn write_table<
INTERSECTION,
)?;

let mut value = String::new();
for row in iter {
let row_iter = row
.into_iter()
.map(|value| value.to_string())
.chain(iter::repeat(String::new()));

writer.write_all(VERTICAL_LINE.as_bytes())?;
for (space, value) in column_widths.iter().copied().map(NonZeroUsize::get).zip(row_iter) {
let value_str = value.to_string();
draw_cell(&mut writer, &value_str, space)?;

let mut row_iter = row.into_iter();
for space in column_widths.iter().copied().map(NonZeroUsize::get) {
if let Some(col) = row_iter.next() {
write!(&mut value, "{}", col).expect("formatting to a string shouldn't fail");
}
draw_cell(&mut writer, &value, space)?;
value.clear();
}

writer.write_all("\n".as_bytes())?;
}

Expand Down