Rust डिज़ाइन पैटर्न
(rust-unofficial.github.io)Rust भाषा की विशेषताओं और डिज़ाइन का उपयोग करने वाले idiom, design pattern और anti-pattern का संकलन
Idioms
-
format!के साथ strings को जोड़ना -
Constructor
-
Defaulttrait -
Collections smart pointers हैं
-
Destructors में finalisation
-
mem::replace(_) -
On-Stack Dynamic Dispatch
-
Optionपर iterate करना -
Variables को closure में pass करना
-
Extensibility के लिए privacy
-
आसान doc initialization
-
अस्थायी mutability
Design Patterns
-
Builder
-
Structs को compose करना
-
Fold
-
Newtype
-
RAII Guards
-
छोटे crates को प्राथमिकता दें
-
unsafety को छोटे modules में सीमित रखें
-
Visitor
Anti-patterns
-
#[deny(warnings)] -
Deref Polymorphism
1 टिप्पणियां
Rust pattern सीखने का एक थोड़ा आसान तरीका यह है कि,
अपने लिखे हुए crate की शुरुआत में
#![warn(clippy::all)]डालने की सिफारिश की जाती है। यह मूल रूप से Rust के linter को चलाकर कोड की जांच करता है और तरह-तरह की सिफारिशें दिखाने वाला विकल्प है।
https://github.com/rust-lang/rust-clippy
यहाँ देखें तो 400 से ज़्यादा lint रजिस्टर किए गए हैं।