Function oneio::read_lines

source ·
pub fn read_lines(
    path: &str
) -> Result<Lines<BufReader<Box<dyn Read + Send>>>, OneIoError>
Expand description

Reads lines from a file specified by the given path.

§Arguments

  • path - A string slice that represents the path of the file to read.

§Returns

A Result containing a Lines iterator of String lines or a OneIoError indicating the error.

§Example

use std::io::BufRead;
use std::io::BufReader;
const TEST_TEXT: &str = "OneIO test file.
This is a test.";

let lines = oneio::read_lines("https://spaces.bgpkit.org/oneio/test_data.txt.gz").unwrap()
    .map(|line| line.unwrap()).collect::<Vec<String>>();

assert_eq!(lines.len(), 2);
assert_eq!(lines[0].as_str(), "OneIO test file.");
assert_eq!(lines[1].as_str(), "This is a test.");