yggdrasil-cli 0.2.5

Yggdrasil is a project flattener and diff engine that turns any subset of your codebase into a single AI-ready codex (index + contents), or compares snapshots with annotated diffs.
/// Count lines in a file, returning 0 if unreadable.
pub fn count_lines(path: &str) -> usize {
    std::fs::read_to_string(path)
        .map(|contents| contents.lines().count())
        .unwrap_or(0)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_count_lines_basic() {
        let tmpfile = "test_count_lines.txt";
        std::fs::write(tmpfile, "a\nb\nc\n").unwrap();

        assert_eq!(count_lines(tmpfile), 3);

        std::fs::remove_file(tmpfile).unwrap();
    }
}