Skip to content

Commit 7fbba65

Browse files
committed
Implement with_config for snip
1 parent 32df740 commit 7fbba65

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

libchisel/src/snip.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,28 @@ impl<'a> ChiselModule<'a> for Snip {
3434
}
3535
}
3636

37+
// TODO: consider making this a generic helper?
38+
fn check_bool_option(config: &HashMap<String, String>, option: &str, default: bool) -> bool {
39+
if let Some(value) = config.get(option) {
40+
value == "true"
41+
} else {
42+
default
43+
}
44+
}
45+
3746
impl ModuleConfig for Snip {
3847
fn with_defaults() -> Result<Self, ModuleError> {
3948
Ok(Snip::new())
4049
}
4150

42-
fn with_config(_config: &HashMap<String, String>) -> Result<Self, ModuleError> {
43-
// FIXME: expose the options
44-
Err(ModuleError::NotSupported)
51+
fn with_config(config: &HashMap<String, String>) -> Result<Self, ModuleError> {
52+
let mut options = wasm_snip::Options::default();
53+
options.snip_rust_fmt_code = check_bool_option(&config, "snip_rust_fmt_code", true);
54+
options.snip_rust_panicking_code =
55+
check_bool_option(&config, "snip_rust_panicking_code", true);
56+
options.skip_producers_section =
57+
check_bool_option(&config, "skip_producers_section", true);
58+
Ok(Snip { 0: options })
4559
}
4660
}
4761

0 commit comments

Comments
 (0)