add option to statically disable decimal mode#47
Conversation
|
the cfg! macro checks for the condition at runtime. Did you intend to do that? There's also a config attribute for compile-time checks (https://doc.rust-lang.org/rust-by-example/attribute/cfg.html). On a more general note, how about we put the setting behind a feature flag? This way, library users can decide to enable it if they like. The syntax is quite similar. |
|
I did not intend to check that flag at runtime! Thanks for the catch. I'm learning about conditional compilation in Rust as I go here so bear with. |
|
Okay, CI is failing but it's nothing to do with this code I've just changed. I'll take a look in the morning. |
825f0d2 to
e2c730f
Compare
|
Here, the tests pass again. I pushed a commit to master and then rebased this branch; hope that's okay (It looks to me like the issue is a lint was added to clippy since the last commit to master) |
c403c30 to
8de65ac
Compare
|
Here, I think this branch is ready. What do you think? |
|
From my experience, features are usually phrased "permissively", so I'd change the feature name to just #[cfg(not(feature = "disable_decimal_mode"))]becomes #[cfg(feature = "decimal_mode")]At a later point in time we could consider grouping those features into more generic "emulation modes" — one for NMOS and one for CMOS for example. We could add the missing instructions for CMOS then as well. Let's keep it simple for now, though. 😉 |
|
Oh and if we want to enable decimal mode by default, we can add it to the list of default features: default = ["decimal_mode"] |
|
Oh I see, that's better yes I agree. But how do we put in |
|
To disable default features, you can pass As described in https://doc.rust-lang.org/cargo/commands/cargo-test.html#feature-selection. |
|
I suppose so, but in the future we'd want something like |
|
Ah, the common way is to first disable all default features and then re-enabling the ones under test, e.g. The same is done in the Granted, it gets a little tedious with many features, but it's mostly a CI thing as normal users would probably just enable one feature in the end — we can combine features into more general features to make that easier if we like. 😉 If we get to a point where testing all combinations gets awkward, we can list them in a |
|
How's this? |
|
Great, looks good to me. Thanks a lot @omarandlorraine. |
So I've never looked at conditional compilation before in Rust. Maybe I got something wrong here. But the tests still pass.