From 4b99fb70fa61addf2373a460d6d5c7fe82e19f5a Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Mon, 19 Aug 2024 11:45:25 -0700 Subject: [PATCH 1/1] Start connecting stuff --- src/lib.rs | 18 ++++++++++-------- src/main.rs | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) 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()); } -- 2.44.1