I get the feeling, and shooting for idiomatic on a rewrite is definitely wrong.
That being said, "idiomatic" is more just saying "clean and familiar". It's using the right language features in the right places.
For example, you could write something like this
fn add_double(a: f64, b: f64) -> f64 {
return a + b;
}
fn add_float(a: f32, b: f32) -> f32 {
return a + b;
}
But that's not idiomatic. Idiomatic would look something like this fn add<T: std::ops::Add<Output = T>>(a: T, b: T) -> T {
return a + b;
}
The benefit of the idiomatic approach is now you have a function which handles a bunch of types from u32, to f64 and it also handles custom types and traits which implement the add ops.The first method is what you might write if you were, for example, translating from C to Rust. It isn't idiomatic but it's easy to do.
The other thing to realize is that compiler authors optimize for idiomatic. The more you do things in a strange fashion, the more likely you are to stumble over a way of writing code which isn't being looked at when the language team is looking at performance and compile time optimizations.
There's nothing wrong with non-idiomatic code per say. However, part of learning a language is learning the idioms. It makes you better at that language.
Pedantic: