Skip to content

Commit 134914b

Browse files
authored
Merge pull request #1416 from ejose19/ej/genericsNewTypeDes
Add destructuring example to generics new type
2 parents 9ce6bf9 + a48ec1d commit 134914b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/generics/new_types.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ fn main() {
4040

4141
Uncomment the last print statement to observe that the type supplied must be `Years`.
4242

43-
To obtain the `newtype`'s value as the base type, you may use tuple syntax like so:
43+
To obtain the `newtype`'s value as the base type, you may use the tuple or destructuring syntax like so:
4444
```rust, editable
4545
struct Years(i64);
4646
4747
fn main() {
4848
let years = Years(42);
49-
let years_as_primitive: i64 = years.0;
49+
let years_as_primitive_1: i64 = years.0; // Tuple
50+
let Years(years_as_primitive_2) = years; // Destructuring
5051
}
5152
```
5253

0 commit comments

Comments
 (0)