|
56 | 56 | /// types.
|
57 | 57 | ///
|
58 | 58 | /// Generic implementations, such as for [`Box<T>`][box] (which is generic over
|
59 |
| -/// every type) should be careful to few methods, since the target type |
60 |
| -/// is unknown and therefore every method could collide with one on the target |
61 |
| -/// type, causing confusion for users. `Box<T>` has few methods (though |
62 |
| -/// several associated functions), partly for this reason. |
63 |
| -/// |
64 |
| -/// Specific implementations, such as for [`String`][string] (which only |
65 |
| -/// implements for `Target = str`) can have many methods, since avoiding |
| 59 | +/// every type and dereferences to `T`) should be careful to provide few or no |
| 60 | +/// methods, since the target type is unknown and therefore every method could |
| 61 | +/// collide with one on the target type, causing confusion for users. |
| 62 | +/// `impl<T> Box<T>` has no methods (though several associated functions), |
| 63 | +/// partly for this reason. |
| 64 | +/// |
| 65 | +/// Specific implementations, such as for [`String`][string] (whose `Deref` |
| 66 | +/// implementation has `Target = str`) can have many methods, since avoiding |
66 | 67 | /// collision is much easier. `String` and `str` both have many methods, and
|
67 | 68 | /// `String` additionally behaves as if it has every method of `str` because of
|
68 |
| -/// deref coercion. |
| 69 | +/// deref coercion. The implementing type may also be generic while the |
| 70 | +/// implementation is still specific in this sense; for example, [`Vec<T>`][vec] |
| 71 | +/// dereferences to `[T]`, so methods of `T` are not applicable. |
69 | 72 | ///
|
70 | 73 | /// Consider also that deref coericion means that deref traits are a much larger
|
71 | 74 | /// part of a type's public API than any other trait as it is implicitly called
|
|
94 | 97 | /// [type coercions]: ../../reference/type-coercions.html
|
95 | 98 | /// [box]: ../../alloc/boxed/struct.Box.html
|
96 | 99 | /// [string]: ../../alloc/string/struct.String.html
|
| 100 | +/// [vec]: ../../alloc/vec/struct.Vec.html |
97 | 101 | /// [rc]: ../../alloc/rc/struct.Rc.html
|
98 | 102 | /// [cow]: ../../alloc/borrow/enum.Cow.html
|
99 | 103 | ///
|
|
0 commit comments