Skip to content

Instantly share code, notes, and snippets.

Created September 21, 2015 16:57
Show Gist options
  • Save anonymous/dae0d40e08e758bf7bd4 to your computer and use it in GitHub Desktop.
Save anonymous/dae0d40e08e758bf7bd4 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
struct ModGuard {
val: u32,
display: &'static str
}
fn get_fizzbuzz_guards() -> Vec<ModGuard> {
vec![
ModGuard{val: 3, display: "Fizz"},
ModGuard{val: 5, display: "Buzz"}]
}
fn generate_str(x: u32) -> String {
let v = get_fizzbuzz_guards();
let mut s = String::from("");
for i in 0..v.len() {
if (i % &v[i].val == 0) {
s.push_str(v[i].display);
}
}
if (s.len() == 0) {
x.to_string()
} else {
s.to_string()
}
}
fn doit() {
for i in 1..101 {
println!("{}", generate_str(i));
}
}
fn main() {
let v = get_fizzbuzz_guards();
for i in 0..v.len() {
println!("{} {}", v[i].display, v[i].val);
}
doit() ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment