Need help with understanding features

I am new to rust. I am going through the cargo book, on the features chapter there is a concept that I am unable understand.
It is mentioned that if a optional dependency will be included only if a feature uses it.


In this screenshot rgb will be enabled if if something else has enabled the rgb dependency.
My doubt is even if serde(feature) uses rgb why will it be enabled if something else has enabled the rgb dependency.

It won't. All that enabling the serde feature does in relation to the rgb dependency is that it will enable its serde feature, only if some other feature has enabled the rgb crate in the first place. If no other feature enables the rgb crate as a dependency, the serde feature won't enable rgb and the rgb?/serde expression becomes a no op, unlike rgb/serde, which would enable the rgb dependency, with the serde feature (the difference between these two being the ? operator behind the crate name).

1 Like

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.