Hacker News new | ask | show | jobs
by tialaramex 332 days ago
Unlike C++ all Rust's methods already can be used this way

    '5'.is_digit(10) // Is literally the same as
    char::is_digit('5', 10) // this
Basically all a "method" is in Rust is an associated function where the first parameter has the magic keyword self instead of needing a real name and type.

Rust even has guidelines recommending you consider e.g. &self rather than having an associated function whose first argument has type &Self, but noting that you should not do this if your type has "smart pointer" behaviour where users expect to call methods on the inner value instead. For example Box and Arc provide associated functions but not methods.