HiveBrain v1.2.0
Get Started
← Back to all entries
gotcharustCritical

What's the difference between self and Self?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
selfandbetweenthedifferencewhat

Problem

I haven't come across Self in the documentation, only in the source code. The documentation only uses self.

Solution

self when used as first method argument, is a shorthand for self: Self. There are also &self, which is equivalent to self: &Self, and &mut self, which is equivalent to self: &mut Self.

Self in method arguments is syntactic sugar for the receiving type of the method (i.e. the type whose impl this method is in). This also allows for generic types without too much repetition.

Context

Stack Overflow Q#32304595, score: 122

Revisions (0)

No revisions yet.