Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

`Static methods no longer require the `static` keyword and instead are distinguished by the lack of a `self` parameter`

Man, am I the only one who really doesn't like implicit things like this?



This change improves consistency between implementations and modules. `impl MyType { … }` is now just like `mod my_module { … }`, except that you can define methods inside `impl` declarations by including a self parameter.

For example:

    struct MyType { … }
    impl MyType { pub fn foo() { … } }
    mod my_module { pub fn foo() { … } }
    fn main() {
        MyType::foo(); // works
        my_module::foo(); // works too
    }


Well, it does kind of make sense. If you never access anything from self then for all intent and purposes there is no reason the function shouldn't be static. That's just my initial perspective reading your comment, not knowing much about the language, so I might be missing some possible scenario this would actually result in a runtime error.


Actually I think its much more explicit that self is ALWAYS passed as a parameter, or it doesn't exist.


Your comment is funny since the other part of the change you cited is the introduction of explicit self.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: