Higher Ranked Trait Bounds (HRTB) article appears to be out of date
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 2.3k
- Forks
- 325
- PR merge metrics
- No merged PRs in 30d
Description
This article seems to be out of date since the stipulation in its early example is easily modified slightly to be valid Rust as demonstrated here on the Rust Playground. Perhaps I am missing something.
As the article states:
// NOTE: `&'b data.0` and `'x: {` is not valid syntax!
struct Closure<F> {
data: (u8, u16),
func: F,
}
impl<F> Closure<F>
// where F: Fn(&'??? (u8, u16)) -> &'??? u8,
{
fn call<'a>(&'a self) -> &'a u8 {
(self.func)(&self.data)
}
}
fn do_it<'b>(data: &'b (u8, u16)) -> &'b u8 {
&'b data.0 // <--- not valid Rust
}
fn main() {
'x: { // <-- not valid Rust
let clo = Closure {
data: (0, 1),
func: do_it
};
println!("{}", clo.call());
}
}
How on earth are we supposed to express the lifetimes on F's trait bound?
We need to provide some lifetime there, but the lifetime we care about can't
be named until we enter the body of call!
However the following is possible...
struct Closure<F> {
data: (u8, u16),
func: F,
}
impl<'a, F> Closure<F>
where F: Fn(&'a (u8, u16)) -> &'a u8,
{
fn call(&'a self) -> &'a u8 {
(self.func)(&self.data)
}
}
fn do_it<'b>(data: &'b (u8, u16)) -> &'b u8 {
&data.0
}
fn main() {
let clo = Closure {
data: (0, 1),
func: do_it
};
println!("{}", clo.call());
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the HRTB article and running the linked Rust Playground example on the stated edition. Compare the article's early example with the demonstrated valid form and confirm the lifetime behavior before updating the article's explanation and code so the examples accurately describe current Rust syntax.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100