Feature flags should be designed with granularity to ensure dependencies are only required when absolutely necessary. When adding functionality that requires additional dependencies, create separate features rather than adding those dependencies to existing features.
Feature flags should be designed with granularity to ensure dependencies are only required when absolutely necessary. When adding functionality that requires additional dependencies, create separate features rather than adding those dependencies to existing features.
Key principles:
Example:
# GOOD: Granular feature with minimal dependencies
[features]
rt = ["tokio/rt", "tokio/sync", "futures-util"]
join-map = ["rt", "hashbrown"] # Separate feature for hashbrown dependency
# BAD: Requiring hashbrown for all rt users
[features]
rt = ["tokio/rt", "tokio/sync", "futures-util", "hashbrown"]
This approach keeps the dependency tree minimal for users who don’t need specific functionality, improving compile times and reducing potential version conflicts. When considering target-specific configurations, ensure dependencies are properly scoped to the relevant target and features (e.g., #[cfg(all(target_os = "linux", feature = "rt"))]
).
Enter the URL of a public GitHub repository