@@ -651,16 +651,24 @@ mod if_keyword {}
651
651
652
652
#[ doc( keyword = "impl" ) ]
653
653
//
654
- /// Implement some functionality for a type.
654
+ /// Implementations of functionality for a type, or a type implementing some functionality.
655
+ ///
656
+ /// There are two uses of the keyword `impl`:
657
+ /// * An `impl` block is an item that is used to implement some functionality for a type.
658
+ /// * An `impl Trait` in a type-position can be used to designate a type that implements a trait called `Trait`.
659
+ ///
660
+ /// # Implementing Functionality for a Type
655
661
///
656
662
/// The `impl` keyword is primarily used to define implementations on types. Inherent
657
663
/// implementations are standalone, while trait implementations are used to implement traits for
658
664
/// types, or other traits.
659
665
///
660
- /// Functions and consts can both be defined in an implementation . A function defined in an
661
- /// `impl` block can be standalone, meaning it would be called like `Foo::bar ()`. If the function
666
+ /// An implementation consists of definitions of functions and consts . A function defined in an
667
+ /// `impl` block can be standalone, meaning it would be called like `Vec::new ()`. If the function
662
668
/// takes `self`, `&self`, or `&mut self` as its first argument, it can also be called using
663
- /// method-call syntax, a familiar feature to any object oriented programmer, like `foo.bar()`.
669
+ /// method-call syntax, a familiar feature to any object-oriented programmer, like `vec.len()`.
670
+ ///
671
+ /// ## Inherent Implementations
664
672
///
665
673
/// ```rust
666
674
/// struct Example {
@@ -680,6 +688,17 @@ mod if_keyword {}
680
688
/// self.number
681
689
/// }
682
690
/// }
691
+ /// ```
692
+ ///
693
+ /// It matters little where an inherent implementation is defined;
694
+ /// its functionality is in scope wherever its implementing type is.
695
+ ///
696
+ /// ## Trait Implementations
697
+ ///
698
+ /// ```rust
699
+ /// struct Example {
700
+ /// number: i32,
701
+ /// }
683
702
///
684
703
/// trait Thingy {
685
704
/// fn do_thingy(&self);
@@ -692,11 +711,19 @@ mod if_keyword {}
692
711
/// }
693
712
/// ```
694
713
///
714
+ /// It matters little where a trait implementation is defined;
715
+ /// its functionality can be brought into scope by importing the trait it implements.
716
+ ///
695
717
/// For more information on implementations, see the [Rust book][book1] or the [Reference].
696
718
///
697
- /// The other use of the `impl` keyword is in `impl Trait` syntax, which can be seen as a shorthand
698
- /// for "a concrete type that implements this trait". Its primary use is working with closures,
699
- /// which have type definitions generated at compile time that can't be simply typed out.
719
+ /// # Designating a Type that Implements Some Functionality
720
+ ///
721
+ /// The other use of the `impl` keyword is in `impl Trait` syntax, which can be understood to mean
722
+ /// "any (or some) concrete type that implements Trait".
723
+ /// It can be used as the type of a variable declaration,
724
+ /// in [argument position](https://rust-lang.github.io/rfcs/1951-expand-impl-trait.html)
725
+ /// or in [return position](https://rust-lang.github.io/rfcs/3425-return-position-impl-trait-in-traits.html).
726
+ /// One pertinent use case is in working with closures, which have unnameable types.
700
727
///
701
728
/// ```rust
702
729
/// fn thing_returning_closure() -> impl Fn(i32) -> bool {
0 commit comments