Skip to content

Commit 91cb3eb

Browse files
committed
Fix doc tests
1 parent 66b7561 commit 91cb3eb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/rust-2021/prelude.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Some users invoke methods on a `dyn Trait` value where the method name overlaps
8585

8686
```rust
8787
mod submodule {
88-
trait MyTrait {
88+
pub trait MyTrait {
8989
// This has the same name as `TryInto::try_into`
9090
fn try_into(&self) -> Result<u32, ()>;
9191
}
@@ -114,23 +114,25 @@ ensures that we're calling `try_into` on the `dyn MyTrait` which can only refer
114114
Many types define their own inherent methods with the same name as a trait method. For instance, below the struct `MyStruct` implements `from_iter` which shares the same name with the method from the trait `FromIterator` found in the standard library:
115115

116116
```rust
117+
use std::iter::IntoIterator;
118+
117119
struct MyStruct {
118120
data: Vec<u32>
119121
}
120122

121123
impl MyStruct {
122124
// This has the same name as `std::iter::FromIterator::from_iter`
123-
fn from_iter(iter: impl Iterator<Item = u32>) -> Self {
125+
fn from_iter(iter: impl IntoIterator<Item = u32>) -> Self {
124126
Self {
125-
data: iter.collect()
127+
data: iter.into_iter().collect()
126128
}
127129
}
128130
}
129131

130-
impl FromIterator<u32> for MyStruct {
132+
impl std::iter::FromIterator<u32> for MyStruct {
131133
fn from_iter<I: IntoIterator<Item = u32>>(iter: I) -> Self {
132134
Self {
133-
data: iter.collect()
135+
data: iter.into_iter().collect()
134136
}
135137
}
136138
}

0 commit comments

Comments
 (0)