#line #comments

lineio

A simple line reader for files - skipping blank lines and comments

3 releases

new 0.1.2 Mar 23, 2025
0.1.1 Mar 22, 2025
0.1.0 Mar 22, 2025

#37 in #comments

Download history 318/week @ 2025-03-19

318 downloads per month

MIT/Apache

6KB

lineio

Very simple file interface, to parse things a line at a time, skipping blank lines, and lines with a hash mark in the first column.

Lots of EDA input files are line-by-line formatted, with a fixed structure, and comments are with the hash mark. Rather than rebuilding a file reader every time (and having to include the use descriptions, and whatnot), just a simple wrapper. Call getline to get a line, unwrap as needed. The new function takes a string filename.

Example

Here's a simple example of reading in a file.

use lineio::LineIO;

fn main() {
    let mut lineio = match LineIO::new(&"test.txt".to_string()) {
        Ok(reader) => reader,
        Err(error) => {panic!("File opening error: {error:?}");}
    };
    loop {
        let s = match lineio.getline() {
            Ok(str) => str,
            Err(_error) => break,
        };
        println!("Read {}", s);
    }
}

lib.rs:

LineIO is a light-weight line-by-line input library, with the ability to skip over lines that begin with a hash mark, or that are blank.

As part of my research, I deal with a lot of input files that have data organized by line, and with intermixed blank lines and comments. Rather than rebuilding a parser input each time, the functionality is wrapped up in the crate.

There are also convenience functions to turn a line into either a vector of floating point numbers, or a vector of usize, i32, or u32.

While the library is called LineIO, it currently only handles input.

You can use this as follows:

use lineio::LineIO;

fn main() {
    let mut lineio = match LineIO::new(&"test.txt".to_string()) {
       Ok(reader) => reader,
       Err(error) => {panic!("File opening error: {error:?}");}
   };
   loop {
       let s = match lineio.getline() {
           Ok(str) => str,
           Err(_error) => break,
       };
       println!("Read {}", s);
   }
}

No runtime deps