First of: don’t use include!() in that way, please!
This may be the way to do it in C, but
include! is not the ‘rustic’ way.
There are very sensible reasons to separate your code in multiple files, e.g. programmer readability.
But if you wish to hide this internal organisation from your users, the ‘rustic’ way of doing it is with
pub use, which re-exports the functions. Good example in this in the excellent StackOverflow Answer:
read more about Rust’s module system in the Book, 2nd ed.
second: this Rust-Internals thread discusses (at great length) why
tl;dr: It’s complicated because
f32 has some edge-cases where equality is fishy, such as
NaN != NaN.
The reason why you cannot
impl Hash for f32 is due to the “Coherence Rules”.
To prevent conflicting impl’s, you can only impl something if either
A) you are the “boss” of the type being
B) you are the “boss” of the type being
impl'd for (e.g.
Being “the boss” means that you define it in your crate.
These rules ensure that there can only ever be ONE location in the entire Rust world that defines the impl, so you’ll never get errors along the lines of "Bob
impls hash for f32, but so do Alice, Joe, Henry and Eve, all are different, which one should I use?"
This is a good thing because your code can never “suddenly” stop compiling if you add a dependency. (e.g. you have Bob’s impl, but later add Alice’s dependency; the Coherence Rules prevent other people breaking your code.)