I think OP's original code is the most intuitive and ergonomic solution. Rust is a procedural, mutation based language because our computers works in this way. The difference from other mutation-based language is Rust makes mutation explicit and encourages to isolate it in language level, so there's no reason to avoid mutation if it compiles.
Ergonomics is the process of designing or arranging workplaces, products and systems so that they fit the people who use them.
The point about ergonomics is that humans are all different, one has to adapt things to fit the human and the job they are doing so that things work well and painlessly.
The original solution is OK if that's it. What if one expected to expand that from 3 tests to a thousand? That's a lot of "if"s to write. Then an imperative loop or functional iterator may be called for.
yep, as always it depends. that is why I like to make software that can be changed easily because it seems that software always needs to be changed when used in real world cases
pub fn raindrops(n: u32) -> String {
let a = if n % 3 == 0 { "Pling" } else { "" };
let b = if n % 5 == 0 { "Plang" } else { "" };
let c = if n % 7 == 0 { "Plong" } else { "" };
let result = String::new() + a + b + c;
if result.len() == 0 {
return n.to_string();
}
result
}