Skip to content

Commit 3e94c98

Browse files
committed
Make JSON and YAML formats optional
1 parent 5adb84d commit 3e94c98

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99

1010
- Make binary dependencies optional
11+
- Make JSON and YAML formats optional
12+
- Bump MSRV to 1.60
1113

1214
## [v0.24.0] - 2022-05-12
1315

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ path = "src/main.rs"
3737
required-features = ["bin"]
3838

3939
[features]
40-
default = ["bin"]
40+
default = ["bin", "json", "yaml"]
4141
bin = ["dep:clap", "dep:clap_conf", "dep:env_logger"]
42+
json = ["dep:serde_json"]
43+
yaml = ["dep:serde_yaml"]
4244

4345
[dependencies]
4446
cast = "0.3"
@@ -51,8 +53,8 @@ quote = "1.0"
5153
proc-macro2 = "1.0"
5254
anyhow = "1.0"
5355
thiserror = "1.0"
54-
serde_json = "1.0.79"
55-
serde_yaml = "0.8.23"
56+
serde_json = { version = "1.0.79", optional = true }
57+
serde_yaml = { version = "0.8.23", optional = true }
5658

5759
[dependencies.svd-parser]
5860
features = ["expand"]

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,10 @@ pub fn load_from(input: &str, config: &crate::util::Config) -> Result<svd::Devic
582582
svd_parser::parse_with_config(input, &parser_config)
583583
.with_context(|| "Error parsing SVD XML file".to_string())?
584584
}
585+
#[cfg(feature = "yaml")]
585586
SourceType::Yaml => serde_yaml::from_str(input)
586587
.with_context(|| "Error parsing SVD YAML file".to_string())?,
588+
#[cfg(feature = "json")]
587589
SourceType::Json => serde_json::from_str(input)
588590
.with_context(|| "Error parsing SVD JSON file".to_string())?,
589591
};

src/util.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ impl Default for Target {
8888
#[derive(Clone, Copy, PartialEq, Debug)]
8989
pub enum SourceType {
9090
Xml,
91+
#[cfg(feature = "yaml")]
9192
Yaml,
93+
#[cfg(feature = "json")]
9294
Json,
9395
}
9496

@@ -102,9 +104,11 @@ impl SourceType {
102104
/// Make a new [`Source`] from a given extension.
103105
pub fn from_extension(s: &str) -> Option<Self> {
104106
match s {
107+
"svd" | "xml" => Some(Self::Xml),
108+
#[cfg(feature = "yaml")]
105109
"yml" | "yaml" => Some(Self::Yaml),
110+
#[cfg(feature = "json")]
106111
"json" => Some(Self::Json),
107-
"svd" | "xml" => Some(Self::Xml),
108112
_ => None,
109113
}
110114
}

0 commit comments

Comments
 (0)