@@ -52,24 +52,20 @@ the _associated items_ to the implementing type.
52
52
53
53
Inherent implementations associate the contained items to the
54
54
implementing type. Inherent implementations can contain [ associated
55
- functions] (including methods), [ associated types ] , and [ associated
56
- constants ] . They cannot contain associated type aliases.
55
+ functions] (including methods) and [ associated constants ] . They cannot
56
+ contain associated type aliases.
57
57
58
- [ associated functions ] : associated-items.html#associated-functions-and-methods
59
- [ associated types ] : associated-items.html#associated-types
60
- [ associated constants ] : associated-items.html#associated-constants
61
-
62
- The path to an associated item is: any path to the implementing type,
58
+ The [ path] to an associated item is: any path to the implementing type,
63
59
followed by the path to the associate item within the inherent
64
60
implementation.
65
61
66
- Note that the path to the module containing the inherent
67
- implementation does not allow access to the associate item, unless the
68
- implementing type is re-exported from the same location.
69
-
70
62
``` rust
71
63
pub mod color {
72
64
pub struct Color (pub u8 , pub u8 , pub u8 );
65
+
66
+ impl Color {
67
+ pub const WHITE : Color = Color (255 , 255 , 255 );
68
+ }
73
69
}
74
70
75
71
mod values {
@@ -83,9 +79,10 @@ mod values {
83
79
84
80
pub use self :: color :: Color ;
85
81
fn main () {
86
- color :: Color :: red (); // actual path to the implementing type
82
+ color :: Color :: WHITE ; // actual path to the implementing type and impl in the same module
83
+ color :: Color :: red (); // impl blocks in different modules are still accessed through a path to the type
87
84
Color :: red (); // rexported paths to the implementing type also work
88
- // bright_theme ::Color::red(); // Does not work, because use in `theme ` is not pub
85
+ // values ::Color::red(); // Does not work, because use in `values ` is not pub
89
86
}
90
87
```
91
88
@@ -225,9 +222,12 @@ attributes].
225
222
[ _Visibility_ ] : visibility-and-privacy.html
226
223
[ _WhereClause_ ] : items/generics.html#where-clauses
227
224
[ trait ] : items/traits.html
225
+ [ associated functions ] : associated-items.html#associated-functions-and-methods
226
+ [ associated constants ] : associated-items.html#associated-constants
228
227
[ attributes ] : attributes.html
229
228
[ `cfg` ] : conditional-compilation.html
230
229
[ `deprecated` ] : attributes.html#deprecation
231
230
[ `doc` ] : attributes.html#documentation
231
+ [ path ] : paths.html
232
232
[ the lint check attributes ] : attributes.html#lint-check-attributes
233
233
[ Unsafe traits ] : items/traits.html#unsafe-traits
0 commit comments