File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -51,10 +51,36 @@ The nominal type is called the _implementing type_ and the associable items are
51
51
the _ associated items_ to the implementing type.
52
52
53
53
Inherent implementations associate the contained items to the implementing type.
54
- The path of an associated item consists of a path to the implementing type followed by
54
+ The path to an associated item is: any path to the implementing type followed by
55
55
the associate item's path component. Inherent implementations cannot contain
56
56
associated type aliases.
57
57
58
+ Note that the path to the module containing the inherent
59
+ implementation does not allow access to the associate item, unless the
60
+ implementing type is re-exported from the same location.
61
+
62
+ ``` rust
63
+ pub mod color {
64
+ pub struct Color (pub u8 , pub u8 , pub u8 );
65
+ }
66
+
67
+ mod values {
68
+ use super :: color :: Color ;
69
+ impl Color {
70
+ pub fn red () -> Color {
71
+ Color (255 , 0 , 0 )
72
+ }
73
+ }
74
+ }
75
+
76
+ pub use self :: color :: Color ;
77
+ fn main () {
78
+ color :: Color :: red (); // actual path to the implementing type
79
+ Color :: red (); // rexported paths to the implementing type also work
80
+ // bright_theme::Color::red(); // Does not work, because use in `theme` is not pub
81
+ }
82
+ ```
83
+
58
84
A type can also have multiple inherent implementations. An implementing type
59
85
must be defined within the same crate as the original type definition.
60
86
You can’t perform that action at this time.
0 commit comments