Skip to content

Commit

Permalink
Merge pull request #1416 from ejose19/ej/genericsNewTypeDes
Browse files Browse the repository at this point in the history
Add destructuring example to generics new type
  • Loading branch information
marioidival authored Mar 22, 2021
2 parents 9ce6bf9 + a48ec1d commit 134914b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/generics/new_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ fn main() {

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

To obtain the `newtype`'s value as the base type, you may use tuple syntax like so:
To obtain the `newtype`'s value as the base type, you may use the tuple or destructuring syntax like so:
```rust, editable
struct Years(i64);
fn main() {
let years = Years(42);
let years_as_primitive: i64 = years.0;
let years_as_primitive_1: i64 = years.0; // Tuple
let Years(years_as_primitive_2) = years; // Destructuring
}
```

Expand Down

0 comments on commit 134914b

Please sign in to comment.