rust_voice_chat_room/protocol/src/lib.rs

40 lines
992 B
Rust
Raw Normal View History

use std::{collections::VecDeque, fs::File, io::Read};
pub const BUFFER_LENGTH: usize = 1024;
#[derive(Debug, Clone)]
struct TOML {
header: String,
fields: VecDeque<String>,
}
fn naive_toml_parser(file_location: &str) -> TOML {
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::<VecDeque<&str>>();
let header = toml_ingredients
.pop_front()
.unwrap()
.replace('[', "")
.replace(']', "")
.trim_end()
.to_string();
let fields = toml_ingredients
.iter()
.map(|ingredient| {
ingredient
.split_once('=')
.unwrap()
.1
.replace('"', "")
.trim()
.to_string()
})
.collect();
TOML { header, fields }
}