Skip to content

Implementing generic trait for a generic type concretely: snippet error? #27

@EdmundsEcho

Description

@EdmundsEcho

I believe there is a mistake in the sample code in the https://brson.github.io/rust-anthology/1/rust-reuse-and-recycle.html.

self in the following snippet, is type Generic<T> so must reference the data therein:

// Incorrect

// Implementing a generic trait for a generic type generically.
// Note that we have two generic types in play; T and U.
impl<T: Equal<U>, U> Equal<Generic<U>> for Generic<T> {
    fn equal(&self, other: &Generic<U>) -> bool {
       self.equal(&other.data)  // <<< should be self.data.equal(&other.data)
    }
}

// correct
impl<T: Equal<U>, U> Equal<Generic<U>> for Generic<T> {
    fn equal(&self, other: &Generic<U>) -> bool {
       self.data.equal(&other.data)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions