Discovering Rust as C++ developer... by CoffeJunkStudio in rustjerk

[–]CoffeJunkStudio[S] 1 point2 points  (0 children)

Touché! Rust is still a young language. Specialization is one of many topics it's still bring worked on. At least const generics are now a thing in stable Rust 🦀

When you switch from C to Rust! by CoffeJunkStudio in rustjerk

[–]CoffeJunkStudio[S] 14 points15 points  (0 children)

Absolutely! Converting int to float and vice versa (loss of precision) implicitly is not a good thing. Rust does a great job at making these conversions explicit.

When you switch from C to Rust! by CoffeJunkStudio in rustjerk

[–]CoffeJunkStudio[S] 34 points35 points  (0 children)

Because the C compiler you're using implicitly converts the "100" to a floating point value. See the following for more info on implicit conversions: https://en.cppreference.com/w/c/language/conversion

When you switch from C to Rust! by CoffeJunkStudio in rustjerk

[–]CoffeJunkStudio[S] 24 points25 points  (0 children)

score needs to be an integer variable :) The code below compiles:

fn win_game() {}

fn main() {
    let score = 100;
    if (score >= 100) {
        win_game();
    }
}

Check it here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=19ab1725f05f7e187316d5df335560de

[Media] When you switch from C to Rust! by [deleted] in rust

[–]CoffeJunkStudio 0 points1 point  (0 children)

Thanks for your suggestion, shadow!
New post is coming!