My Rust project has examples that are only relevant to certain features.
I can ignore the main function with:
#[cfg(feature = "foo")]
fn main() {
But other statements that depend on the feature cause errors when I run cargo test
. So I have to use a number of cfg attribute statements on functions and use statements to disable code that depends on the feature.
Is there a way to just ignore an entire example file based on the feature configuration?
Also, because main is hidden without the feature, cargo test
has this error:
error: main function not found
So this isn't a good solution.
Disabling all form elements HTML form elements have an attribute called disabled that can be set using javascript. If you are setting it in HTML you can use disabled="disabled" but if you are using javascript you can simply set the property to true or false .
To disable div element and everything inside with CSS, we set the pointer-events CSS property of the div to none . to disable pointer events on the div with pointer-events set to none with CSS.
Divs can't be disabled. Only form and form elems. Actually in Quirks-mode IE can disable a div , but it only grays button texts, it doesn't prevent events firing.
document. getElementById("dcalc"). disabled = true; javascript.
Make more specific use of the #[cfg]
directive, providing both a main()
when foo
is enabled, and a main()
when foo
is not:
extern crate blah;
// other code which will still compile even without "foo" feature
#[cfg(feature = "foo")]
fn main() {
use blah::OnlyExistsWithFoo;
// code which requires "foo" feature
}
#[cfg(not(feature = "foo"))]
fn main() {
// empty main function for when "foo" is disabled
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With