|
35 | 35 | ///
|
36 | 36 | /// For more information on what `as` is capable of, see the [Reference]
|
37 | 37 | ///
|
38 |
| -/// [Reference]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions |
| 38 | +/// [Reference]: |
| 39 | +/// https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions |
39 | 40 | /// [`crate`]: keyword.crate.html
|
40 | 41 | /// [`use`]: keyword.use.html
|
41 | 42 | mod as_keyword { }
|
@@ -90,7 +91,8 @@ mod as_keyword { }
|
90 | 91 | ///
|
91 | 92 | /// [`static`]: keyword.static.html
|
92 | 93 | /// [pointer]: primitive.pointer.html
|
93 |
| -/// [Rust Book]: https://doc.rust-lang.org/stable/book/2018-edition/ch03-01-variables-and-mutability.html#differences-between-variables-and-constants |
| 94 | +/// [Rust Book]: |
| 95 | +/// https://doc.rust-lang.org/stable/book/2018-edition/ch03-01-variables-and-mutability.html#differences-between-variables-and-constants |
94 | 96 | /// [Reference]: https://doc.rust-lang.org/reference/items/constant-items.html
|
95 | 97 | mod const_keyword { }
|
96 | 98 |
|
@@ -221,7 +223,8 @@ mod enum_keyword { }
|
221 | 223 | ///
|
222 | 224 | /// For more information on FFI, check the [Rust book] or the [Reference].
|
223 | 225 | ///
|
224 |
| -/// [Rust book]: https://doc.rust-lang.org/book/second-edition/ch19-01-unsafe-rust.html#using-extern-functions-to-call-external-code |
| 226 | +/// [Rust book]: |
| 227 | +/// https://doc.rust-lang.org/book/second-edition/ch19-01-unsafe-rust.html#using-extern-functions-to-call-external-code |
225 | 228 | /// [Reference]: https://doc.rust-lang.org/reference/items/external-blocks.html
|
226 | 229 | mod extern_keyword { }
|
227 | 230 |
|
@@ -364,7 +367,8 @@ mod fn_keyword { }
|
364 | 367 | /// [`impl`]: keyword.impl.html
|
365 | 368 | /// [`break`]: keyword.break.html
|
366 | 369 | /// [`IntoIterator`]: iter/trait.IntoIterator.html
|
367 |
| -/// [Rust book]: https://doc.rust-lang.org/book/2018-edition/ch03-05-control-flow.html#looping-through-a-collection-with-for |
| 370 | +/// [Rust book]: |
| 371 | +/// https://doc.rust-lang.org/book/2018-edition/ch03-05-control-flow.html#looping-through-a-collection-with-for |
368 | 372 | /// [Reference]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops
|
369 | 373 | mod for_keyword { }
|
370 | 374 |
|
@@ -442,10 +446,72 @@ mod for_keyword { }
|
442 | 446 | ///
|
443 | 447 | /// [`match`]: keyword.match.html
|
444 | 448 | /// [`let`]: keyword.let.html
|
445 |
| -/// [Rust book]: https://doc.rust-lang.org/stable/book/2018-edition/ch03-05-control-flow.html#if-expressions |
| 449 | +/// [Rust book]: |
| 450 | +/// https://doc.rust-lang.org/stable/book/2018-edition/ch03-05-control-flow.html#if-expressions |
446 | 451 | /// [Reference]: https://doc.rust-lang.org/reference/expressions/if-expr.html
|
447 | 452 | mod if_keyword { }
|
448 | 453 |
|
| 454 | +#[doc(keyword = "impl")] |
| 455 | +// |
| 456 | +/// The implementation-defining keyword. |
| 457 | +/// |
| 458 | +/// The `impl` keyword is primarily used for defining implementations on types. There are two kinds |
| 459 | +/// of implementations: Inherent implementations and trait implementations. Inherent |
| 460 | +/// implementations define functions that operate on a type, known in object-oriented languages as |
| 461 | +/// methods. Trait implementations are used to give a type a trait, and implement any of the |
| 462 | +/// required associated items or methods that it requires. |
| 463 | +/// |
| 464 | +/// ```rust |
| 465 | +/// struct Example { |
| 466 | +/// number: i32, |
| 467 | +/// } |
| 468 | +/// |
| 469 | +/// impl Example { |
| 470 | +/// fn boo() { |
| 471 | +/// println!("boo! Example::boo() was called!"); |
| 472 | +/// } |
| 473 | +/// |
| 474 | +/// fn answer(&mut self) { |
| 475 | +/// self.number += 42; |
| 476 | +/// } |
| 477 | +/// |
| 478 | +/// fn get_number(&self) -> i32 { |
| 479 | +/// self.number |
| 480 | +/// } |
| 481 | +/// } |
| 482 | +/// |
| 483 | +/// trait Thingy { |
| 484 | +/// fn do_thingy(&self); |
| 485 | +/// } |
| 486 | +/// |
| 487 | +/// impl Thingy for Example { |
| 488 | +/// fn do_thingy(&self) { |
| 489 | +/// println!("doing a thing! also, number is {}!", self.number); |
| 490 | +/// } |
| 491 | +/// } |
| 492 | +/// ``` |
| 493 | +/// |
| 494 | +/// For more information on implementations, see the [Rust book][book1] or the [Reference]. |
| 495 | +/// |
| 496 | +/// The other use of the `impl` keyword is in `impl Trait` syntax, which can be seen as a shorthand |
| 497 | +/// for "a concrete type that implements this trait". Its primary use is working with closures, |
| 498 | +/// which have type definitions generated at compile time that can't be simply typed out. |
| 499 | +/// |
| 500 | +/// ```rust |
| 501 | +/// fn thing_returning_closure() -> impl Fn(i32) -> bool { |
| 502 | +/// println!("here's a closure for you!"); |
| 503 | +/// |x: i32| x % 3 == 0 |
| 504 | +/// } |
| 505 | +/// ``` |
| 506 | +/// |
| 507 | +/// For more information on `impl Trait` syntax, see the [Rust book][book2]. |
| 508 | +/// |
| 509 | +/// [book1]: https://doc.rust-lang.org/stable/book/2018-edition/ch05-03-method-syntax.html |
| 510 | +/// [Reference]: https://doc.rust-lang.org/reference/items/implementations.html |
| 511 | +/// [book2]: |
| 512 | +/// https://doc.rust-lang.org/stable/book/2018-edition/ch10-02-traits.html#returning-traits |
| 513 | +mod impl_keyword { } |
| 514 | + |
449 | 515 | #[doc(keyword = "let")]
|
450 | 516 | //
|
451 | 517 | /// The `let` keyword.
|
|
0 commit comments