docs

你正在阅读 v0.1.2 的文档。Nabi 0.1.2 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#E0145: named some type not defined by its module

type X = some Tr; is one concrete type, and the functions of X's module that return X (fn make() -> X { .. }) give it from their bodies. The module has none, they give different types, or one is generic. Add a function in that module that returns X, return the same type from every one (have the others call the first), or keep the type parameter out of it: a generic opaque result is written fn f<T>(..) -> some Tr.

nabi
type Evens = some Iterator<Item = i64>;

println("no evens yet");
error[E0145]: `Evens` has no defining function
  --> main.nabi:1:1
   |
 1 | type Evens = some Iterator<Item = i64>;
   | ^^^^
   |
   = help: a function in this module that returns `Evens` gives its type: `fn make() -> Evens { .. }`

Add a function that returns it:

nabi
type Evens = some Iterator<Item = i64>;

fn evens(n: i64) -> Evens {
    (0..n).filter(|x| x % 2 == 0)
}

println(evens(7).count());
4

Related: E0069 trait bound not satisfied, E0146 named some type used as its concrete type

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