-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Higher Ranked Trait Bounds (HRTB) article appears to be out of date #412
Comments
I don't think its outdated because when passing a liftetime to the |
I think it would be nice to see this explained though, because I did have the question. Why would you not declare the lifetime in on the I know there's a difference, but not what that is. |
Actually after I originally posted my comment, I've looked into HRTBs a little deeper and have found a very interesting answer on stackoverflow, essentially what HRTBs are doing is that the lifetime in Now if go back to our example in the book, edit it a bit and use the lifetime on the function itself without HRTB struct Closure<F> {
data: (u8, u16),
func: F,
}
impl<'a, F> Closure<F>
where F: Fn(&'a (u8, u16)) -> u8,
{
fn call(&'a self) -> u8 {
let local = (10, 15);
(self.func)(&local)
}
}
fn do_it<'b>(data: &'b (u8, u16)) -> u8 {
data.0
}
fn main() {
let clo = Closure {
data: (0, 1),
func: do_it
};
println!("{}", clo.call());
} if you run the following you'll get
p.s. this is why I think the author of that page wrote "If we try to naively desugar this code" :) You can find the detailed explanation with nice examples here - https://stackoverflow.com/a/35595491/10791422 |
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:
However the following is possible...
The text was updated successfully, but these errors were encountered: