docs

您正在閱讀 v0.1.0 的文件。Nabi 0.1.0 已停止支援。 最新版本:v0.1.3 →

本頁尚未翻譯,以下為英文原文。

#E0073: impl item is not in the trait

A trait impl defines a method or an associated type the trait does not declare. Remove it, or move a method to an inherent impl of the type. A trait's generic parameters are not associated types: write them in the header, impl IndexSet<usize, V> for T, not as type V = ...

nabi
trait Shape { fn area(self) -> f64; }
struct Sq { s: f64; }
impl Shape for Sq {
    fn area(self) -> f64 { self.s * self.s }
    fn side(self) -> f64 { self.s }
}
error[E0073]: method `side` is not a member of trait `Shape`
  --> main.nabi:3:1
   |
 3 | impl Shape for Sq {
   | ^^^^

Move the method to an inherent impl:

nabi
trait Shape { fn area(self) -> f64; }
struct Sq { s: f64; }
impl Shape for Sq {
    fn area(self) -> f64 { self.s * self.s }
}
impl Sq {
    fn side(self) -> f64 { self.s }
}
println(f"{Sq { s: 3.0 }.side()}");
3

Related: E0072 impl is missing a trait item, E0074 impl item does not match the trait

Found a mistake? Edit this page on GitHub. Last updated