#E0146: 구체 타입으로 쓴 이름 있는 some 타입
type X = some Tr;을 선언한 모듈 밖에서 X는 Tr만 가진 따로인 타입입니다. 구체 타입은 이름 붙일 수 없고, 다른 타입의 값은 X가 아닙니다. 값은 X로 두고(필드, let x: X, List<X>, 매개변수 모두 담을 수 있음) Tr로 쓰며, 새 값은 X의 모듈 함수에서 얻으세요. 구체 타입이 필요한 코드는 그 모듈에 둡니다.
nabi
mod shapes {
pub type Count = some Display;
pub fn count() -> Count { 3 }
}
let n: i64 = shapes::count();
error[E0146]: mismatched types: `let n` expects `i64`, found `Count`: outside `shapes`, `Count` is opaque --> main.nabi:7:14 | 7 | let n: i64 = shapes::count(); | ^^^^^^^^^^^^^^^ | = help: only `shapes` sees what `Count` is: keep the value as `Count` and use it through its bounds, get one from `shapes::count`, or move this code into `shapes`
Count로 두세요.
nabi
mod shapes {
pub type Count = some Display;
pub fn count() -> Count { 3 }
}
let n: shapes::Count = shapes::count();
println(f"{n} shapes");
3 shapes
관련 코드: E0040 타입 불일치, E0145 모듈이 정의하지 않은 이름 있는 some 타입
잘못된 곳이 있나요? GitHub에서 이 페이지 고치기. 마지막 수정