X-Git-Url: http://git.scottworley.com/tablify/blobdiff_plain/58b5f36de045c760efa51b21a6d841f5b62558db..4b99fb70fa61addf2373a460d6d5c7fe82e19f5a:/src/lib.rs 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)]