14 पॉइंट द्वारा xguru 2021-01-04 | 1 टिप्पणियां | WhatsApp पर शेयर करें

Rust भाषा की विशेषताओं और डिज़ाइन का उपयोग करने वाले idiom, design pattern और anti-pattern का संकलन

Idioms

  1. format! के साथ strings को जोड़ना

  2. Constructor

  3. Default trait

  4. Collections smart pointers हैं

  5. Destructors में finalisation

  6. mem::replace(_)

  7. On-Stack Dynamic Dispatch

  8. Option पर iterate करना

  9. Variables को closure में pass करना

  10. Extensibility के लिए privacy

  11. आसान doc initialization

  12. अस्थायी mutability

Design Patterns

  1. Builder

  2. Structs को compose करना

  3. Fold

  4. Newtype

  5. RAII Guards

  6. छोटे crates को प्राथमिकता दें

  7. unsafety को छोटे modules में सीमित रखें

  8. Visitor

Anti-patterns

  1. #[deny(warnings)]

  2. Deref Polymorphism

1 टिप्पणियां

 
xguru 2021-01-04

Rust pattern सीखने का एक थोड़ा आसान तरीका यह है कि,

अपने लिखे हुए crate की शुरुआत में

#![warn(clippy::all)]

डालने की सिफारिश की जाती है। यह मूल रूप से Rust के linter को चलाकर कोड की जांच करता है और तरह-तरह की सिफारिशें दिखाने वाला विकल्प है।

https://github.com/rust-lang/rust-clippy

यहाँ देखें तो 400 से ज़्यादा lint रजिस्टर किए गए हैं।