In Rust: what is the difference between self and Self (lowercase and uppercase)?
Hi everyone! I started learning Rust and came across a strange thing: in code I often see `self` and `Self`, but they are used differently. I'm confused.
Here is an example from the Rust book that I'm trying to understand:
```rust
struct Point {
x: f64,
y: f64,
}
impl Point {
fn new(x: f64, y: f64) -> Self {
Self { x, y }
}
fn distance(&self, other: &Self) -> f64 {
let dx = self.x - other.x;
let dy = self.y - other.y;
(dx * dx + dy * dy).sqrt()
}
}
```
I see that in `fn new` it returns `Self`, and in `fn distance` the parameter `other` has type `&Self`. Inside the methods I access fields via `self.x`. But aren't `self` and `Self` the same thing? Why are they written differently?
My question: what is the fundamental difference?