add library to load data

This commit is contained in:
unintendedfraud
2023-12-03 18:11:29 +01:00
parent bad5f5e70e
commit 15fb43e600
62 changed files with 52 additions and 18 deletions
+8
View File
@@ -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]
+17
View File
@@ -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;
}