Skip to content

Commit 79cab22

Browse files
committed
Remove redundant example on structs and capturing
What this example is showing is how one field of a struct can be captured while another is not (when using rest patterns). However, the example above demonstrates this with tuples, and there are no interesting differences between tuple fields and struct fields in this case.
1 parent 2a42ae1 commit 79cab22

File tree

1 file changed

+0
-19
lines changed

1 file changed

+0
-19
lines changed

src/types/closure.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -261,25 +261,6 @@ println!("{:?}", x.1);
261261
c();
262262
```
263263

264-
```rust
265-
struct Example {
266-
f1: String,
267-
f2: String,
268-
}
269-
270-
let e = Example {
271-
f1: String::from("first"),
272-
f2: String::from("second"),
273-
};
274-
let c = || {
275-
let Example { f2, .. } = e; // captures `e.f2` ByValue
276-
};
277-
// Field f2 cannot be accessed since it is moved into the closure.
278-
// Field f1 is still accessible.
279-
println!("{:?}", e.f1);
280-
c();
281-
```
282-
283264
r[type.closure.capture.precision.wildcard.array-slice]
284265
Partial captures of arrays and slices are not supported; the entire slice or array is always captured even if used with wildcard pattern matching, indexing, or sub-slicing.
285266

0 commit comments

Comments
 (0)