From 6c907212b446e1c39ddb6db621bb72c6d07255f6 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 2 Feb 2016 11:15:45 -0500 Subject: [PATCH] Add note about temporaries --- src/doc/book/patterns.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/doc/book/patterns.md b/src/doc/book/patterns.md index 39a9cb1885e..6fd7f4cd475 100644 --- a/src/doc/book/patterns.md +++ b/src/doc/book/patterns.md @@ -196,8 +196,16 @@ let (x, _) = tuple; println!("Tuple is: {:?}", tuple); ``` -In a similar fashion to `_`, you can use `..` in a pattern to disregard -multiple values: +This also means that any temporary variables will be dropped at the end of the +statement: + +```rust +// Here, the String created will be dropped immediately, as it’s not bound: + +let _ = String::from(" hello ").trim(); +``` + +You can also use `..` in a pattern to disregard multiple values: ```rust enum OptionalTuple {