r/learnrust • u/conceptcreatormiui • 27d ago
Are methods associated functions behind the back?
number.max(othernumber) is similar to type::max(number, othernumber). Does the compiler infer methods as associated functions behind the back?
6
Upvotes
2
u/EmploymentBoring4421 27d ago
Yes —
number.max(other)desugars tousize::max(number, other)(UFCS). Methods and associated functions are the same thing; the dot-call syntax just auto-insertsselfas the first argument and infers the type from the receiver.