Associated interface types

An interface may name an associated type with type Name. Each impl binds it with type Name = Concrete, which keeps the related types inside one contract.

Associated types describe a capability's output without adding a free type argument at every use. The binding belongs to the impl and is checked with its methods.

interface Source {
  type Item
  fn count(self: string) -> int
}

struct Numbers { values: [int] }

impl Source for Numbers {
  type Item = int
  fn count(self: Numbers) -> int { self.values.len() }
}

fn main() {}
Output & diagnostics
Edit the source, then Check or Run. Ctrl/⌘+Enter checks.
Ctrl/⌘+Enter checks the current lesson.