docs

#E0074: 트레잇과 맞지 않는 impl 항목

트레잇 impl의 메서드가 매개변수, 반환 타입, throws에서 트레잇의 선언과 다릅니다. 트레잇이 선언한 대로 쓰세요.

nabi
trait Shape { fn area(self) -> f64; }
struct Sq { s: f64; }
impl Shape for Sq {
    fn area(self, scale: f64) -> f64 { self.s * scale }
}
error[E0074]: `area` does not match its declaration in trait `Shape`: it takes 2 parameters where the trait's takes 1
  --> main.nabi:4:5
   |
 4 |     fn area(self, scale: f64) -> f64 { self.s * scale }
   |     ^^
   |
   = help: write `fn area(self) -> f64`

트레잇이 선언한 대로 메서드를 쓰세요.

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

관련 코드: E0072 impl에 빠진 트레잇 항목, E0073 트레잇에 없는 impl 항목

잘못된 곳이 있나요? GitHub에서 이 페이지 고치기. 마지막 수정