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