Use Self where possible (CODE_STYLE.md)

This commit is contained in:
Temirkhan Myrzamadi 2020-01-08 20:46:09 +06:00 committed by GitHub
parent 1053180502
commit 28c5d9f8c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -41,3 +41,49 @@ Good:
/// This function makes a request to Telegram.
pub fn make_request(url: &str) -> String { ... }
```
## Use Self where possible
Bad:
```rust
impl ErrorKind {
fn print(&self) {
ErrorKind::Io => println!("Io"),
ErrorKind::Network => println!("Network"),
ErrorKind::Json => println!("Json"),
}
}
```
Good:
```rust
impl ErrorKind {
fn print(&self) {
Self::Io => println!("Io"),
Self::Network => println!("Network"),
Self::Json => println!("Json"),
}
}
```
<details>
<summary>More examples</summary>
Bad:
```rust
impl<'a> AnswerCallbackQuery<'a> {
pub(crate) fn new<C>(bot: &'a Bot, callback_query_id: C) -> AnswerCallbackQuery<'a>
where
C: Into<String>, { ... }
```
Good:
```rust
impl<'a> AnswerCallbackQuery<'a> {
pub(crate) fn new<C>(bot: &'a Bot, callback_query_id: C) -> Self
where
C: Into<String>, { ... }
```
</details>