refactor: ♻️ toml parser

This commit is contained in:
Ahmet Kaan GÜMÜŞ 2024-11-29 20:31:02 +03:00
parent da01d37a93
commit a8fe214308
3 changed files with 42 additions and 64 deletions

24
src/utils.rs Normal file
View file

@ -0,0 +1,24 @@
use std::{fs::File, io::Read};
pub fn naive_toml_parser(file_location: &str) -> (String, Vec<String>) {
let mut toml_file = File::open(file_location).unwrap();
let mut toml_ingredients = String::default();
toml_file.read_to_string(&mut toml_ingredients).unwrap();
let mut toml_ingredients = toml_ingredients.lines().collect::<Vec<&str>>();
let header = toml_ingredients.remove(0).trim_end().to_string();
let parsed = toml_ingredients
.iter()
.map(|ingredient| {
ingredient
.split_once('=')
.unwrap()
.1
.replace('"', "")
.trim()
.to_string()
})
.collect();
(header, parsed)
}