What do you call static methods in Rust?
⚓ Rust 📅 2025-05-20 👤 surdeus 👁️ 9Technically, an "associated function" is one that's associated with a type; and a "method" is an associated function that takes a self parameter.
What do you call the kind of associated function that doesn't have a self parameter?
I'm working on revisions to the book Programming Rust and trying to decide if we should make a change. In the current edition we use the made-up term "type-associated function":
An
implblock for a given type can also define functions that don't takeselfas an argument at all. These are still associated functions, since they're in animplblock, but they're not methods, since they don't take aselfargument. To distinguish them from methods, we call them type-associated functions.
Using a made-up term is pretty terrible, but "static method" is wrong in two ways (it's neither a static nor a method; discuss) and everything else seems worse ("constructor", "non-method associated function", ...?).
So: What do you call these things in everyday conversation? Maybe we should go with that.
3 posts - 3 participants
🏷️ rust_feed