Skip to content

Commit

Permalink
Add toml_file_is_valid.
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy committed Apr 14, 2024
1 parent 20fdbbd commit cbc7e41
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/util/src/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ pub fn toml_is_valid(toml: String) -> bool {
toml::from_str::<toml::Table>(&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::<toml::Table>(&file).ok())
.is_some()
}

#[byond_fn]
pub fn toml_decode(toml: String) -> ByondResult<ByondValue> {
toml::from_str::<toml::Table>(&toml)
Expand Down

0 comments on commit cbc7e41

Please sign in to comment.