Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable an entire example based on features?

Tags:

rust

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.

like image 664
Arlo Avatar asked Jun 13 '16 06:06

Arlo


People also ask

How do I turn off complete form?

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 .

How do I turn off content in CSS?

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.

How do I make a div disabled?

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.

How do I enable and disable a div in HTML?

document. getElementById("dcalc"). disabled = true; javascript.


1 Answers

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
}
like image 113
SpaceManiac Avatar answered Nov 15 '22 08:11

SpaceManiac