From: Scott Worley Date: Mon, 19 Aug 2024 18:45:25 +0000 (-0700) Subject: Start connecting stuff X-Git-Tag: v0.2.0~13 X-Git-Url: http://git.scottworley.com/tablify/commitdiff_plain/4b99fb70fa61addf2373a460d6d5c7fe82e19f5a?hp=58b5f36de045c760efa51b21a6d841f5b62558db Start connecting stuff --- diff --git a/src/lib.rs b/src/lib.rs index fcf5dc8..8d60eb8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,5 @@ -#[cfg(test)] use std::collections::{HashMap, HashSet}; -#[cfg(test)] use std::io::BufRead; -#[cfg(test)] use std::iter::Iterator; #[derive(Debug, PartialEq, Eq)] @@ -16,7 +13,6 @@ struct Reader>> { row: Option, } impl>> Reader { - #[cfg(test)] fn new(input: Input) -> Self { Self { input: input.enumerate(), @@ -63,12 +59,10 @@ impl>> Iterator for Reader } } -#[cfg(test)] fn read_rows(input: impl std::io::Read) -> impl Iterator> { Reader::new(std::io::BufReader::new(input).lines()) } -#[cfg(test)] fn column_counts(rows: &[RowInput]) -> Vec<(usize, String)> { let mut counts: Vec<_> = rows .iter() @@ -86,8 +80,16 @@ fn column_counts(rows: &[RowInput]) -> Vec<(usize, String)> { counts } -pub fn tablify(_input: &impl std::io::Read) -> String { - String::from("Hello, world!") +/// # Errors +/// +/// Will return `Err` if +/// * there's an i/o error while reading `input` +/// * the log has invalid syntax: +/// * an indented line with no preceding non-indented line +pub fn tablify(input: impl std::io::Read) -> Result { + let rows = read_rows(input).collect::, _>>()?; + let _columns = column_counts(&rows); + Ok(String::from("Hello, world!")) } #[cfg(test)] diff --git a/src/main.rs b/src/main.rs index 95f468f..8cf4859 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,3 @@ fn main() { - print!("{}", tablify::tablify(&std::io::stdin())); + print!("{}", tablify::tablify(std::io::stdin()).unwrap()); }