I'd like to know more about disabling compilation of parts of your crate using features.
I know there is:
#[cfg(feature = "foo")]
pub fn foo() { ... }
which would presumably cause rustc to ignore this function when compiling unless that feature is enabled in Cargo,toml
[dependencies]
my-crate = { version = "0.1.0", features = ["foo"] }
But I don't know if I can specify to not compile a use
d feature that my-crate
depends on:
use external::CanIPleaseNotCompileThis
#[cfg(feature = "bar")]
fn bar() -> impl CanIPleaseNotCompileThis
Sorry for the contrived example!
I think this might be what optional dependencies are for having skimmed this page of the cargo book Specifying Dependencies - The Cargo Book
What I'm really doing, (to avoid the X-Y problem), is have a shared crate that both a client and server (webapp) depend on to share types that can be sent back and forth (i.e. some structs that model the API requests and responses).
I'd like to implement rocket's FromForm for the responses so the server can use it when handling routes
but... rocket won't compile for the wasm32-unknown-unknown target used by my client crate, so if I add rocket as a dependency to the shared crate then I can't build the client at all*
Unless I can "hide it behind a feature". Though apparently "mutually exclusive" use of features is a bad idea
*I get ring build script errors, I did have a quick google and it seems to be a fairly gnarly problem I'd like to avoid