I have in code something like:
#[cfg(fs_extra)]
Where in the crate I am supposed to say:
fs_extra = true
Thanks
I have in code something like:
#[cfg(fs_extra)]
Where in the crate I am supposed to say:
fs_extra = true
Thanks
Cfg values are passed to rustc when you invoke it. For example rustc --cfg fs_extra src/main.rs
. In case you use cargo, you should use #[cfg(feature = "fs_extra")]
instead and add the following to Cargo.toml
:
[features]
fs_extra = []
You can then enable it when building using cargo build --features fs_extra
. Or in case of a dependency you specify it using something like my_dep = { version = "0.1.0", features = ["fs_extra"] }
. See Features - The Cargo Book more more information.
In my .rs file I've put:
#[cfg(feature = "serial_cpy")]
{
cpy_task(paths_from, path_to);
}
In my Cargo.toml I've put:
[features]
serial_cpy = [ ]
Still not working. What am I doing wrong?
Are you building with cargo build --features serial_cpy
?
You can also make it default if you don't want to pass it yourself every time:
[features]
default = ["fs_extra"]
fs_extra = []
Yes
I did that too. Still no luck. I must be doing something wrong.
My Cargo.toml
[features]
defaults = ["serial_cpy"]
serial_cpy = []
My .rs:
#[cfg(feature = "serial_cpy")]//I want this to be active only if I specify it in Cargo.toml
{
cpy_task(paths_from, path_to, counter.clone(),cb);
}
The key should be default
, not defaults
(no S).
That looks correct to me. Have you tried putting eprintln!("test")
or something inside the block to check for sure whether it's being compiled?
Thanks to everyone for taking the time and helping me.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.