How to correctly deprecate a crate feature
Asked Answered
T

1

6

I have a crate that up to now had a feature that will no longer be needed. I'd like to deprecate it, but have no idea how.

My plan so far is to make it a default feature first, but then what?

Taylor answered 6/7, 2019 at 21:27 Comment(1)
Presumably you want to introduce a warning and then some time later, increment the semver and remove the feature completely, so it's a hard error. There isn't really a nice way to do it. A very clumsy approach is to use the feature to enable some code that will trigger a warning. You won't have much control over how that warning looks though. There is the Diagnostics API, which can probably do what you need via a procedural macro, but it is not yet stable.Obcordate
I
2

You can put this on functions that previously depended on this feature:

#[cfg_attr(feature = "unwanted", deprecated(note = "don't use the feature"))]

This will show a warning only if that feature has been enabled. However, the warning will be slightly misleading, as it will point to the function.

When you completely remove the feature, you should increase the major version.

Iberian answered 24/7, 2019 at 10:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.