Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/generics/assoc_items/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ fn difference<A, B, C>(container: &C) -> i32 where
C: Contains<A, B> { ... }

// 使用关联类型
fn difference<C: Contains>(container: &C) -> i32 { ... }
fn difference<C>(container: &C) -> i32 where
C: Contains { ... }
```

让我们使用关联类型来重写上一小节的例子:
Expand Down Expand Up @@ -61,7 +62,9 @@ impl Contains for Container {
fn last(&self) -> i32 { self.1 }
}

fn difference<C: Contains>(container: &C) -> i32 {
fn difference<C>(container: &C) -> i32
where C: Contains
{
container.last() - container.first()
}

Expand Down