@@ -173,7 +173,39 @@ let (x, _, z) = coordinate();
173
173
Here, we bind the first and last element of the tuple to ` x ` and ` z ` , but
174
174
ignore the middle element.
175
175
176
- Similarly, you can use ` .. ` in a pattern to disregard multiple values.
176
+ It’s worth noting that using ` _ ` never binds the value in the first place,
177
+ which means a value may not move:
178
+
179
+ ``` rust
180
+ let tuple : (u32 , String ) = (5 , String :: from (" five" ));
181
+
182
+ // Here, tuple is moved, because the String moved:
183
+ let (x , _s ) = tuple ;
184
+
185
+ // The next line would give "error: use of partially moved value: `tuple`"
186
+ // println!("Tuple is: {:?}", tuple);
187
+
188
+ // However,
189
+
190
+ let tuple = (5 , String :: from (" five" ));
191
+
192
+ // Here, tuple is _not_ moved, as the String was never moved, and u32 is Copy:
193
+ let (x , _ ) = tuple ;
194
+
195
+ // That means this works:
196
+ println! (" Tuple is: {:?}" , tuple );
197
+ ```
198
+
199
+ This also means that any temporary variables will be dropped at the end of the
200
+ statement:
201
+
202
+ ``` rust
203
+ // Here, the String created will be dropped immediately, as it’s not bound:
204
+
205
+ let _ = String :: from (" hello " ). trim ();
206
+ ```
207
+
208
+ You can also use ` .. ` in a pattern to disregard multiple values:
177
209
178
210
``` rust
179
211
enum OptionalTuple {
0 commit comments