Skip to content

Commit

Permalink
feat: parse json to serde_json::Value with feature
Browse files Browse the repository at this point in the history
Signed-off-by: Lachezar Lechev <[email protected]>
  • Loading branch information
elpiel committed Jan 10, 2024
1 parent abf4059 commit f3e2c1d
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 2 deletions.
88 changes: 88 additions & 0 deletions Cargo.lock

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

11 changes: 9 additions & 2 deletions official-addons-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ include = [
"/README.md"
]

[lib]
doctest = false
[features]

default = ["json", "std"]
std = ["serde_json/std", "once_cell/std"]

json = ["serde_json", "once_cell"]

[dependencies]

serde_json = { version = "1", optional = true, default-features = false }
once_cell = { version = "1", optional = true, default-features = false }
26 changes: 26 additions & 0 deletions official-addons-v2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
#[cfg(feature = "json")]
pub use serde_json::Value;
#[cfg(feature = "json")]
use once_cell::sync::Lazy;

/// The JSON file's content
pub const ADDONS: &'static [u8] = include_bytes!("../addons.json");

#[cfg(feature = "json")]
/// The JSON file content but after json validation
pub const ADDONS_JSON: Lazy<Value> =
Lazy::new(|| serde_json::from_slice(ADDONS).expect("Valid JSON"));

// todo: parsed addons manifests

#[cfg(test)]
mod test {
use super::*;

#[test]
#[cfg(feature = "json")]
fn addons_file_is_valid_json() {
let addons_json = ADDONS_JSON.clone();

assert_ne!(addons_json, serde_json::Value::Null);
}
}

0 comments on commit f3e2c1d

Please sign in to comment.