An attribute for deprecation

Minimum Rust version: 1.9

If you're writing a library, and you'd like to deprecate something, you canuse the deprecated attribute:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. #[deprecated(
  4. since = "0.2.1",
  5. note = "Please use the bar function instead"
  6. )]
  7. pub fn foo() {
  8. // ...
  9. }
  10. }

This will give your users a warning if they use the deprecated functionality:

  1. Compiling playground v0.0.1 (file:///playground)
  2. warning: use of deprecated item 'foo': Please use the bar function instead
  3. --> src/main.rs:10:5
  4. |
  5. 10 | foo();
  6. | ^^^
  7. |
  8. = note: #[warn(deprecated)] on by default

Both since and note are optional.

since can be in the future; you can put whatever you'd like, and what's put inthere isn't checked.