Can I mark a function as deprecated?

后端 未结 2 1785
抹茶落季
抹茶落季 2021-01-07 16:12

I\'d like to mark functions/methods as deprecated. I tried to apply the deprecated attribute:

#[deprecated]
fn old_way_of_doing_it() {
<         


        
2条回答
  •  孤城傲影
    2021-01-07 16:54

    Since Rust 1.9.0 (2016 May 26th) you can use the #[deprecated] attribute in your own crates (RFC 1270). The syntax is:

    #[deprecated(since="0.5.0", note="please use `new_method` instead")]
    pub fn old_method() { ..; }
    

    It will throw the following warning whenever you use old_method:

    :6:5: 6:15 warning: use of deprecated item: please use `new_method` instead, #[warn(deprecated)] on by default
    :6     old_method()
                 ^~~~~~~~~~
    

    You may find more information in the RFC.

提交回复
热议问题