use std::{ io::Read, path::Path};
use tokio::{fs::File, io::AsyncReadExt};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NamespaceDefinition {
pub schema: u32,
pub metadata: NamespaceMetadata,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NamespaceMetadata {
pub id: String,
pub name: String,
pub owners: Vec<String>,
}
fn parse_namespace_toml(input: &str) -> NamespaceDefinition {
return toml::from_str(input).unwrap();
}
pub async fn parse_namespace_toml_files(files: Vec<&Path>) -> Vec<NamespaceDefinition> {
let mut r = vec![];
for f in files {
let buf: &mut String = &mut String::new();
File::open(f).await.unwrap().read_to_string(buf).await.unwrap();
r.push(parse_namespace_toml(buf.clone().as_str()));
}
return r;
}