]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0118.md
Auto merge of #66396 - smmalis37:pythontest, r=alexcrichton
[rust.git] / src / librustc_error_codes / error_codes / E0118.md
1 You're trying to write an inherent implementation for something which isn't a
2 struct nor an enum. Erroneous code example:
3
4 ```compile_fail,E0118
5 impl (u8, u8) { // error: no base type found for inherent implementation
6     fn get_state(&self) -> String {
7         // ...
8     }
9 }
10 ```
11
12 To fix this error, please implement a trait on the type or wrap it in a struct.
13 Example:
14
15 ```
16 // we create a trait here
17 trait LiveLongAndProsper {
18     fn get_state(&self) -> String;
19 }
20
21 // and now you can implement it on (u8, u8)
22 impl LiveLongAndProsper for (u8, u8) {
23     fn get_state(&self) -> String {
24         "He's dead, Jim!".to_owned()
25     }
26 }
27 ```
28
29 Alternatively, you can create a newtype. A newtype is a wrapping tuple-struct.
30 For example, `NewType` is a newtype over `Foo` in `struct NewType(Foo)`.
31 Example:
32
33 ```
34 struct TypeWrapper((u8, u8));
35
36 impl TypeWrapper {
37     fn get_state(&self) -> String {
38         "Fascinating!".to_owned()
39     }
40 }
41 ```