Static method vs self method in std API

I noticed that in the std library, some APIs use "static" method that takes an argument of their own type instead of using Self.
Is there a reason of that ?

For example for ManuallyDrop in std::mem - Rust
Why pub unsafe fn take(slot: &mut ManuallyDrop<T>) -> T instead of pub unsafe fn take(slot: &mut Self) -> T ?

This it to avoid ambiguity when the value inside the ManuallyDrop also has a method called take.

You will see this pattern on most types in std that implement the Deref trait.


They are equivalent, inside an impl block Self is an alias to the type you're implementing for. Generally it's just personal preference whether to use one or the other.

If you are instead asking why it isn't defined to take an &mut self parameter (note that this is different than slot: &mut Self! &mut self allows the method call syntax, slot: &mut Self doesn't), then see alice's answer.

Yes, I was asking for the self (lower case). My bad.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.