rust - Can I mark a function as deprecated? -
i'd mark functions/methods deprecated. tried apply deprecated
attribute:
#[deprecated] fn old_way_of_doing_it() {
but yields error:
error: stability attributes may not used outside of standard library
is there way in can have compiler warn consumer of library function deprecated?
i have no experience, i'm considering experimenting compiler plugins , custom attributes, guess require consumer use plugin, maybe unreasonable (or may unreasonable amount of work me implement?)
as side question out of curiosity, why deprecated attribute applicable standard library?
since rust 1.9.0 (2016 may 26th) can use #[deprecated]
attribute in own crates (rfc 1270). syntax is:
#[deprecated(since="0.5.0", note="please use `new_method` instead")] pub fn old_method() { ..; }
it throw following warning whenever use old_method
:
<anon>:6:5: 6:15 warning: use of deprecated item: please use `new_method` instead, #[warn(deprecated)] on default <anon>:6 old_method() ^~~~~~~~~~
you may find more information in rfc.
Comments
Post a Comment