The Rust standard library provides numerous built-in traits. To ensure code correctness, performance, and idiomatic design, follow the specific guidelines provided for each trait implementation or usage. These guidelines cover common pitfalls in implementing traits like Borrow, Default, Copy, Clone, From, Into, Hash, Ord, and Deref.
Available guidelines include:
- **Borrow**: Ensure consistency when implementing `Borrow`.
- **Default**: Use specific type `default()` instead of `Default::default()`; prefer `#[derive(Default)]` over manual implementation.
- **Copy/Clone**: Do not implement `Copy` for iterators; do not call `std::mem::drop` or `std::mem::forgot` on `Copy` or reference types; use `.copied()` instead of `.cloned()` for `Copy` types; avoid manual `Clone` for `Copy` types.
- **Hash/Ord**: Avoid manual `PartialEq` when using `#[derive(Hash)]`; avoid manual `PartialOrd` when using `#[derive(Ord)]`.
- **From/Into**: Implement `From` instead of `Into`.
- **Deref**: Do not use `Deref` to simulate inheritance.