-
-
Save folkengine/c1c8bf84755e735ec540 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or 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 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