From cbc7e412e5f090bfaa4c8c1dd88ebbbbeee4e073 Mon Sep 17 00:00:00 2001 From: Lucy Date: Sun, 14 Apr 2024 11:36:54 -0400 Subject: [PATCH] Add `toml_file_is_valid`. --- crates/util/src/toml.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/util/src/toml.rs b/crates/util/src/toml.rs index 3c68705..5f9c03a 100644 --- a/crates/util/src/toml.rs +++ b/crates/util/src/toml.rs @@ -7,6 +7,14 @@ pub fn toml_is_valid(toml: String) -> bool { toml::from_str::(&toml).is_ok() } +#[byond_fn] +pub fn toml_file_is_valid(path: PathBuf) -> bool { + std::fs::read_to_string(path) + .ok() + .and_then(|file| toml::from_str::(&file).ok()) + .is_some() +} + #[byond_fn] pub fn toml_decode(toml: String) -> ByondResult { toml::from_str::(&toml)