Skip to content

Commit 85df178

Browse files
authored
Merge pull request #401 from JoshBrudnak/master
Combine related paragraphs and add more details for implementations
2 parents f89b762 + 1baeaa8 commit 85df178

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

src/items/implementations.md

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
# Implementations
22

3-
An _implementation_ is an item that associates items with an *implementing type*.
3+
An _implementation_ is an item that associates items with an _implementing type_.
4+
Implementations are defined with the keyword `impl` and contain functions
5+
that belong to an instance of the type that is being implemented or to the
6+
type statically.
47

5-
There are two types of implementations: inherent implementations and [trait]
6-
implementations.
8+
There are two types of implementations:
79

8-
Implementations are defined with the keyword `impl`.
10+
- inherent implementations
11+
- [trait] implementations
912

1013
## Inherent Implementations
1114

1215
An inherent implementation is defined as the sequence of the `impl` keyword,
1316
generic type declarations, a path to a nominal type, a where clause, and a
1417
bracketed set of associable items.
1518

16-
The nominal type is called the *implementing type* and the associable items are
17-
the *associated items* to the implementing type.
18-
19-
Inherent implementations associate the associated items to the implementing
20-
type.
19+
The nominal type is called the _implementing type_ and the associable items are
20+
the _associated items_ to the implementing type.
2121

22+
Inherent implementations associate the contained items to the implementing type.
2223
The associated item has a path of a path to the implementing type followed by
23-
the associate item's path component.
24-
25-
Inherent implementations cannot contain associated type aliases.
26-
27-
A type can have multiple inherent implementations.
24+
the associate item's path component. Inherent implementations cannot contain
25+
associated type aliases.
2826

29-
The implementing type must be defined within the same crate.
27+
A type can also have multiple inherent implementations. An implementing type
28+
must be defined within the same crate as the original type definition.
3029

3130
```rust
3231
struct Point {x: i32, y: i32}
@@ -43,14 +42,14 @@ my_point.log();
4342

4443
## Trait Implementations
4544

46-
A *trait implementation* is defined like an inherent implementation except that
45+
A _trait implementation_ is defined like an inherent implementation except that
4746
the optional generic type declarations is followed by a [trait] followed
48-
by the keyword `for`. <!-- To understand this, you have to back-reference to
49-
the previous section. :( -->
47+
by the keyword `for`. Followed by a path to a nominal type.
5048

51-
The trait is known as the *implemented trait*.
49+
<!-- To understand this, you have to back-reference to the previous section. :( -->
5250

53-
The implementing type implements the implemented trait.
51+
The trait is known as the _implemented trait_. The implementing type
52+
implements the implemented trait.
5453

5554
A trait implementation must define all non-default associated items declared
5655
by the implemented trait, may redefine default associated items defined by the
@@ -105,18 +104,18 @@ be instantiable with the same set of types for the input type parameters. -->
105104
The `Orphan Check` states that every trait implementation must meet either of
106105
the following conditions:
107106

108-
1. The trait being implemented is defined in the same crate.
107+
1. The trait being implemented is defined in the same crate.
109108

110-
2. At least one of either `Self` or a generic type parameter of the trait must
111-
meet the following grammar, where `C` is a nominal type defined
112-
within the containing crate:
109+
2. At least one of either `Self` or a generic type parameter of the trait must
110+
meet the following grammar, where `C` is a nominal type defined
111+
within the containing crate:
113112

114-
```ignore
115-
T = C
116-
| &C
117-
| &mut C
118-
| Box<C>
119-
```
113+
```ignore
114+
T = C
115+
| &C
116+
| &mut C
117+
| Box<C>
118+
```
120119
121120
## Generic Implementations
122121

0 commit comments

Comments
 (0)