From adb6ad43198451d70e6c8624fd344681c9869c85 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Sat, 25 Jan 2020 04:59:37 +0600 Subject: [PATCH] Update CODE_STYLE.md --- CODE_STYLE.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CODE_STYLE.md b/CODE_STYLE.md index 359d4c08..384d7fa4 100644 --- a/CODE_STYLE.md +++ b/CODE_STYLE.md @@ -26,7 +26,7 @@ Good: ``` ## Comments -Comments must describe what your code does and mustn't describe how your code does it and bla-bla-bla. Be sure that your comments follow the grammar, including punctuation, the first capital letter and so on. + 1. Comments must describe what your code does and mustn't describe how your code does it and bla-bla-bla. Be sure that your comments follow the grammar, including punctuation, the first capital letter and so on. Bad: @@ -42,7 +42,7 @@ Good: pub fn make_request(url: &str) -> String { ... } ``` -Also, link resources in your comments when possible: + 2. Also, link resources in your comments when possible: ```rust /// Download a file from Telegram. @@ -115,3 +115,10 @@ C: Into, { ... } ## Naming 1. Avoid unnecessary duplication (`Message::message_id` -> `Message::id` using `#[serde(rename = "message_id")]`). 2. Use a generic parameter name `S` for streams, `Fut` for futures, `F` for functions (where possible). + +## Deriving + 1. Derive `Copy`, `Eq`, `Hash`, `PartialEq`, `Clone`, `Debug` for public types when possible (note: if the default `Debug` implementation is weird, you should manually implement it by yourself). + 2. Derive `Default` when there is an algorithm to get a default value for your type. + +## Misc + 1. Use `Into<...>` only where there exists at least one conversion **and** it will be logically to use.