Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #8 from AffectedArc07/toml2json
Browse files Browse the repository at this point in the history
Adds toml2json helper
  • Loading branch information
marlyn-x86 authored Jun 4, 2021
2 parents 426f80c + ad1c17d commit 4a5f151
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rust-g"
edition = "2018"
version = "0.4.5-P2"
version = "0.4.5-P3"
authors = ["Bjorn Neergaard <[email protected]>"]
repository = "https://github.com/ParadiseSS13/rust-g"
license-file = "LICENSE"
Expand Down Expand Up @@ -32,6 +32,7 @@ serde_derive = { version = "1.0", optional = true }
once_cell = { version = "1.4", optional = true }
mysql = { version = "19.0", optional = true }
dashmap = { version = "3.11", optional = true }
toml = { version = "0.5.8", optional = true }

[features]
default = ["dmi", "log", "git", "http", "sql", "noise"]
Expand All @@ -42,4 +43,5 @@ log = ["chrono"]
url = ["url-dep", "percent-encoding"]
git = ["git2", "chrono"]
http = ["reqwest", "serde", "serde_json", "serde_derive", "once_cell"]
sql = ["mysql", "serde", "serde_derive", "serde_json", "once_cell", "dashmap"]
sql = ["mysql", "serde", "serde_derive", "serde_json", "once_cell", "dashmap"]
toml2json = ["toml", "serde_json"]
8 changes: 8 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ fn main() {
"#).unwrap();
}

// module: sql
if enabled!("TOML2JSON") {
write!(f, r#"
// toml2json stuff //
#define rustg_toml2json(tomlfile) call(RUST_G, "toml2json")(tomlfile)
"#).unwrap();
}

// Version footer
write!(f, "
// RUSTG Version //
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub mod noise_gen;
pub mod sql;
#[cfg(feature = "url")]
pub mod url;
#[cfg(feature = "toml2json")]
pub mod toml2json;

#[cfg(not(target_pointer_width = "32"))]
compile_error!("rust-g must be compiled for a 32-bit target");
9 changes: 9 additions & 0 deletions src/toml2json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::fs;

byond_fn! { toml2json(tomlfile) {
// This error handling may look weird, but trust me
let content = fs::read_to_string(tomlfile).unwrap_or("".to_string()); // If the file doesnt exist, just report back empty toml
let val: toml::Value = toml::from_str(&content).unwrap_or(toml::from_str("").unwrap()); // If the toml is malformed, just report back empty json
let json_data = serde_json::to_string(&val).unwrap();
Some(json_data)
} }

0 comments on commit 4a5f151

Please sign in to comment.