2015-06-10 7 views
24

मैं बहिष्कृत कार्यों/विधियों को चिह्नित करना चाहता हूं। मैं deprecated विशेषता लागू करने की कोशिश की:क्या मैं फ़ंक्शन को बहिष्कृत कर सकता हूं?

#[deprecated] 
fn old_way_of_doing_it() { 

लेकिन यह एक त्रुटि पैदावार:

error: stability attributes may not be used outside of the standard library 

वहाँ एक रास्ता है, जिसमें मैं संकलक हो सकता है मेरे पुस्तकालय के एक उपभोक्ता है कि एक समारोह का बहिष्कार कर रहा है चेतावनी दी ?

मुझे कोई अनुभव नहीं है, लेकिन मैं कंपाइलर प्लगइन्स और कस्टम विशेषताओं के साथ प्रयोग करने पर विचार कर रहा हूं, लेकिन मुझे लगता है कि उपभोक्ता को प्लगइन का उपयोग करने की आवश्यकता होगी, जो शायद अनुचित है (या एक अनुचित राशि हो सकती है मुझे लागू करने के लिए?)

जिज्ञासा से बाहर एक पक्ष सवाल के रूप में, बहिष्कृत विशेषता केवल मानक पुस्तकालय पर क्यों लागू होती है?

उत्तर

16

Rust 1.9.0 (2016 May 26th) के बाद से आप अपने खुद के crates (RFC 1270) में #[deprecated] विशेषता का उपयोग कर सकते हैं। वाक्य रचना है:

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

यह जब भी आप old_method का उपयोग निम्न चेतावनी फेंक देगा:

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

आप आरएफसी में अधिक जानकारी प्राप्त कर सकते हैं।

6

अद्यतन:#[deprecated] वर्तमान में (फरवरी 2016 तक) रात में उपलब्ध है। यह मार्च 2016 की शुरुआत के आसपास स्थिर में उपलब्ध होना चाहिए।

बाहरी पुस्तकालयों में ऐसा करने का कोई तरीका नहीं है।

ऐसा करना बहुत वांछनीय है (मैं निश्चित रूप से इसे कई बार चाहता था), लेकिन मानक लाइब्रेरी द्वारा 1.0 पर आवश्यक कार्यक्षमता पर डिजाइन और कार्यान्वयन प्रयासों पर ध्यान केंद्रित करने के लिए निर्णय लिया गया था, और बाह्य के लिए एक डिजाइन को अनुकूलित करने के लिए स्थगित कर दिया गया था बाद में पुस्तकालयों। RFC यह एक छोटे चर्चा करता है:

It's important to note that these stability attributes are only known to be useful to the standard distribution, because of the explicit linkage to language versions and release channels. [...]. A general mechanism for indicating API stability will be reconsidered in the future.

[...]

With respect to stability attributes and Cargo, the proposed design is very specific to the standard library and the Rust compiler without being intended for use by third-party libraries. It is planned to extend Cargo's own support for features (distinct from Rust features) to enable this form of feature development in a first-class method through Cargo. At this time, however, there are no concrete plans for this design and it is unlikely to happen soon.

वहाँ पुल अनुरोध स्वयं को बहुत जल्दी पर महत्वपूर्ण चर्चा नहीं हुई:

(यही कारण है कि आरएफसी है इसके बारे में जानकारी के लिए कैनोलिक स्रोत।)

I have no experience, but I'm considering experimenting with compiler plugins and custom attributes, but I guess that would require the consumer to also use the plugin, which is maybe unreasonable (or may be an unreasonable amount of work for me to implement?)

हां, उपभोक्ता को प्लगइन का उपयोग करने की आवश्यकता होगी, और मुझे पूरी तरह से यकीन नहीं है कि क्या कंपाइलर प्लगइन के लिए मौजूदा अंतर्निहित #[deprecated] अनुकरण करने के लिए आवश्यक सभी जानकारी प्राप्त करना आसान बनाता है।

संबंधित मुद्दे