14P by xguru 2021-01-04 | favorite | 댓글 1개

러스트 언어의 특이점 및 디자인을 활용한 Idiom 과 Design Pattern, Anti Pattern 정리

Idioms
1. Concatenating Strings with format!
2. Constructor
3. The Default Trait
4. Collections Are Smart Pointers
5. Finalisation in Destructors
6. mem::replace(_)
7. On-Stack Dynamic Dispatch
8. Iterating over an Option
9. Pass Variables to Closure
10. Privacy For Extensibility
11. Easy doc initialization
12. Temporary mutability

Design Patterns
1. Builder
2. Compose Structs
3. Fold
4. Newtype
5. RAII Guards
6. Prefer Small Crates
7. Contain unsafety in small modules
8. Visitor

Anti-patterns
1. #[deny(warnings)]
2. Deref Polymorphism

Rust 패턴을 익히는 조금 편한 방법으로,

작성한 Crate 의 시작부에
ㅤ#![warn(clippy::all)]

를 넣으라는 추천이 있더군요. 기본적으로 Rust 의 linter 를 동작시켜서 코드에 대해서 확인하고 다양한 추천을 보여주도록 하는 옵션입니다.

https://github.com/rust-lang/rust-clippy
여기 보면 400개가 넘는 Lint 들이 등록되어 있습니다.