1 An inherent implementation was defined for something which isn't a struct nor
4 Erroneous code example:
7 impl (u8, u8) { // error: no base type found for inherent implementation
8 fn get_state(&self) -> String {
14 To fix this error, please implement a trait on the type or wrap it in a struct.
18 // we create a trait here
19 trait LiveLongAndProsper {
20 fn get_state(&self) -> String;
23 // and now you can implement it on (u8, u8)
24 impl LiveLongAndProsper for (u8, u8) {
25 fn get_state(&self) -> String {
26 "He's dead, Jim!".to_owned()
31 Alternatively, you can create a newtype. A newtype is a wrapping tuple-struct.
32 For example, `NewType` is a newtype over `Foo` in `struct NewType(Foo)`.
36 struct TypeWrapper((u8, u8));
39 fn get_state(&self) -> String {
40 "Fascinating!".to_owned()