Implementing generic trait for a generic type concretely: snippet error?
- Dominant language
- Shell
- Stars
- 1.5k
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Description
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` so must reference the `data` therein:
```rust
// Incorrect
// Implementing a generic trait for a generic type generically.
// Note that we have two generic types in play; T and U.
impl, U> Equal> for Generic {
fn equal(&self, other: &Generic) -> bool {
self.equal(&other.data) // <<< should be self.data.equal(&other.data)
}
}
// correct
impl, U> Equal> for Generic {
fn equal(&self, other: &Generic) -> bool {
self.data.equal(&other.data)
}
}
```
Contributor guide
Research direction
Open the linked Rust Anthology page and inspect the generic trait implementation snippet. Compare the marked incorrect expression with the corrected version using the data fields; done means the published example uses the corrected expression and remains valid Rust.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100