[comment]: # "markdown: { smartypants: true }" ## Shadowing
### Useful Links
Slides:
https://beyondcodebootcamp.github.io/
Video:
https://youtu.be/ID_GOES_HERE
AJ ONeal
[@\_beyondcode](https://twitter.com/@_beyondcode)
[youtube.com/coolaj86](https://youtube.com/coolaj86)
Dangerous Wrong Thinker Equal Opportunity Offender Technophobic Technologist Extraordinairé
Utah Node.js Utah Rust Twitch.tv/coolaj86
Like, Sub, & Follow
(if this is useful, or entertaining)
# Shadowing
When you want to _reuse_
When you want to _reuse_ the _name_ of a variable.
```rs [1-2] let answer = "42"; let answer = answer.parse::
().unwrap(); ```
## Scenario
All command line args are _strings_.
(even when they're numbers)
```rs [1-7] let ageStr = env::args().skip(1).next() .unwrap(); println!("age: {}", age); let ageNum = ageStr.parse::
() .unwrap(); println!("age: {}", age); ```
```rs [1] let ageStr = env::args().skip(1).next() .unwrap(); println!("age: {}", age); let ageNum = ageStr.parse::
() .unwrap(); println!("age: {}", age); ```
```rs [5] let ageStr = env::args().skip(1).next() .unwrap(); println!("age: {}", age); let ageNum = ageStr.parse::
() .unwrap(); println!("age: {}", age); ```
But
storing _type information_ in a _name_
... is lame.
```rs [1-11] // type of 'age' is string let age = env::args().skip(1).next() .unwrap(); println!("age: {}", age); // different memory location for new 'age', as int! // (the other age may still be useful through other references) let age = age.parse::
() .unwrap(); println!("age: {}", age); ```
```rs [1-2] // type of 'age' is string let age = env::args().skip(1).next() .unwrap(); println!("age: {}", age); // different memory location for new 'age', as int! // (the other age may still be useful through other references) let age = age.parse::
() .unwrap(); println!("age: {}", age); ```
```rs [6-8] // type of 'age' is string let age = env::args().skip(1).next() .unwrap(); println!("age: {}", age); // different memory location for new 'age', as int! // (the other age may still be useful through other references) let age = age.parse::
() .unwrap(); println!("age: {}", age); ```
Like, Sub, & Follow
(if you wannu)
Thanks.
FIN