In my experience taking a term that is widely used and attempting to give it a more specific meaning doesn’t end well. If people are using “method” interchangeably with “associated function” right now it will be an endless battle of trying to make people stop using the term “sloppily” when it isn’t sloppy it was just the original meaning.
I could understand method = associated function whose first parameter is named
self
, so it can be called likeself.foo(…)
. This would mean functions likeVec::new
aren’t methods. But the author’s requirement also excludes functions that take generic arguments likeExtend::extend
.However, even the above definition gives old terminology new meaning. In traditionally OOP languages, the functions belonging to a class are “static methods” and the functions belonging to an instance are “instance methods”. Static methods are considered methods even though
self
may not be defined. So I think that translating OOP terminology into Rust, all associated functions would be considered methods, and those with/without method call syntax are instance/static methods.Unfortunately I think that some people misuse “method” to only refer to “instance method”, so to be 100% unambiguous the terms have to be:
- Associated function: function in an
impl
block. - Static method: associated function whose first argument isn’t
self
(even if it takesSelf
under a different name, likeBox::leak
). - Instance method: associated function whose first argument is
self
, so it can be called likeself.foo(…)
. - Object-safe method: a method callable from a trait object.
I’d call instance methods just methods, it fits more into how the word is commonly used.
The omission is just way to easy not to use.
- Associated function: function in an