add library to load data
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "util"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,17 @@
|
||||
use std::{fs::File, io::Read};
|
||||
|
||||
pub fn get_data(path: &str) -> Vec<String> {
|
||||
let mut data = match File::open(path) {
|
||||
Ok(file) => file,
|
||||
Err(err) => panic!("failed to read the data file: {:?}", err),
|
||||
};
|
||||
|
||||
let mut content = String::new();
|
||||
data.read_to_string(&mut content)
|
||||
.ok()
|
||||
.expect("failed to parse file");
|
||||
|
||||
let lines: Vec<String> = content.split("\n").map(|l| l.to_string()).collect();
|
||||
|
||||
return lines;
|
||||
}
|
||||
Reference in New Issue
Block a user