Skip to content

Self is not explained in Chapter 10.2 #1228

@pgalkin

Description

@pgalkin

As far as I know Self was first used in Chapter 10.2, Listing 10-17. It is easy to infer that it refers to Pair, but still it's better to mention it. Furthermore, it seems to be required and cannot be substituted for Pair or Pair<T>. I think it should be noted as well, because you can substitute concrete type for Self in associated functions for non-generic types, like was done in Chapter 5.3, section on Associated Functions. There we have

impl Rectangle {
    fn square(size: u32) -> Rectangle {
        Rectangle { width: size, height: size }
    }
}

which seems to be identical to

impl Rectangle {
    fn square(size: u32) -> Self {
        Self { width: size, height: size }
    }
}

Also, it would be good to explain the difference between Self and self.

By the way, I haven't read further than Chapter 10.2, so everything might be explained in later chapters, I don't know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions