Created
April 2, 2021 10:41
-
-
Save gemcave/96bd3ad75a213a45a0b2433696351b08 to your computer and use it in GitHub Desktop.
frontendmasters rust lesson2 solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct City { | |
description: String, | |
residents: u64, | |
is_coastal: bool | |
} | |
fn new_city(residents: u64, is_coastal: bool) -> City { | |
if is_coastal { | |
City { | |
description: format!("a *coastal* city of approximately {} residents", residents), | |
residents, | |
is_coastal | |
} | |
} else { | |
City { | |
description: format!("a *coastal* city of approximately {} residents", residents), | |
residents, | |
is_coastal: false | |
} | |
} | |
} | |
fn main() { | |
let rustville: City = new_city(1200000, false); | |
if rustville.is_coastal { | |
println!("It is a coastal city."); | |
} else { | |
println!("It is not a coastal city."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment