3 ms·
`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
by wrl 14y ago
`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?
- efuquen 14y agoWell, 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.
- deleted 14y ago[deleted]
- jeremyjh 14y agoActually I think its much more explicit that self is ALWAYS passed as a parameter, or it doesn't exist.
- pcwalton 14y agoThis 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 }
- kzrdude 14y agoYour comment is funny since the other part of the change you cited is the introduction of explicit self.