An inherent implementation was defined for something which isn't a struct, enum, union, or trait object.
Erroneous code example:
#![allow(unused)]
fn main() {
impl<T> T { // error: no nominal type found for inherent implementation
fn get_state(&self) -> String {
// ...
}
}
} To fix this error, please implement a trait on the type or wrap it in a struct. Example:
#![allow(unused)]
fn main() {
// we create a trait here
trait LiveLongAndProsper {
fn get_state(&self) -> String;
}
// and now you can implement it on T
impl<T> LiveLongAndProsper for T {
fn get_state(&self) -> String {
"He's dead, Jim!".to_owned()
}
}
} Alternatively, you can create a newtype. A newtype is a wrapping tuple-struct. For example, NewType is a newtype over Foo in struct NewType(Foo). Example:
#![allow(unused)]
fn main() {
struct TypeWrapper<T>(T);
impl<T> TypeWrapper<T> {
fn get_state(&self) -> String {
"Fascinating!".to_owned()
}
}
}
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/error_codes/E0118.html