brson / brson/rust-anthology

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

Open
#27 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.