Skip to content

Instantly share code, notes, and snippets.

@gemcave
Created April 2, 2021 10:41
Show Gist options
  • Save gemcave/96bd3ad75a213a45a0b2433696351b08 to your computer and use it in GitHub Desktop.
Save gemcave/96bd3ad75a213a45a0b2433696351b08 to your computer and use it in GitHub Desktop.
frontendmasters rust lesson2 solution
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