docs

v0.1.0 문서를 보고 있습니다. 이 버전은 더 이상 지원하지 않습니다. 최신 릴리스: v0.1.3 →

#E0076: 외부 타입에 대한 외부 트레잇의 impl

트레잇 impl에는 트레잇이나 타입 중 하나가 이 패키지에 정의되어 있어야 합니다. 외부 타입을 직접 만든 구조체로 감싸고 그 구조체에 트레잇을 구현하세요.

nabi
impl Display for List<i32> {
    fn fmt(self, ref f: Formatter) throws (FmtError) { try f.write_str("list"); }
}
error[E0076]: `impl Display for List<i32>`: neither the trait nor the type is defined in this package (orphan rule)
  --> main.nabi:1:1
   |
 1 | impl Display for List<i32> {
   | ^^^^

외부 타입을 직접 만든 구조체로 감싸세요.

nabi
struct Nums { xs: List<i32>; }
impl Display for Nums {
    fn fmt(self, ref f: Formatter) throws (FmtError) { try f.write_str(f"{self.xs.len()} numbers"); }
}
println(f"{Nums { xs: [1, 2] }}");
2 numbers

관련 코드: E0075 충돌하는 구현

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