lib.rs
const PREFIX: &str = "Pl";
const FACTORS_VOWELS: [(u32, char); 3] = [(3, 'i'), (5, 'a'), (7, 'o')];
const SUFFIX: &str = "ng";
const MAX_STRING_LENGTH: usize = (PREFIX.len() + 1 + SUFFIX.len()) * FACTORS_VOWELS.len();
pub fn raindrops(n: u32) -> String {
let mut out = String::with_capacity(MAX_STRING_LENGTH);
FACTORS_VOWELS.iter().for_each(|&(factor, vowel)| {
if (n % factor).eq(&0) {
out.push_str(PREFIX);
out.push(vowel);
out.push_str(SUFFIX);
}
});
if out.is_empty() {
n.to_string()
} else {
out
}
}