Live data from Hacker News

An alternative introduction to Rust

words.steveklabnik.com

91–94 of 94 posts

Re: An alternative introduction to Rust

#91
post #89

Earlier quoted context omitted.

I've seen this example several times now, and I never got why it was so bad: it's mostly an objection to the namespace qualification syntax if anything. It would actually be written: use std::ops::Neg; struct Foo where P: Neg + 'a, ::Output: 'a { foo: &'a Bar , } And with further proposed improvements it would be: use std::ops::Neg; struct Foo where P: Neg + 'a, P::Output: 'a { foo: &'a Bar , } Not bad. It's saying "…

I think namespace qualification syntax and trait bounds make it more confusing ` ::Output: 'a` gives me eye cancer and my intuition is if `P: Neg + 'a` then `P::Output: 'a` is implied (why would it not have that bound if P does?) the Neg trait's Output IS Self (as Neg)! Why is the bound not transitive?

> `::Output: 'a` gives me eye cancer and my intuition is if `P: Neg + 'a` then `P::Output: 'a` is implied (why would it not have that bound if P does?)

What if the output of the unary minus method was say, a constant 'static? This is a reasonable thing for a function to want to do in general. (Probably not for Neg in particular, but obviously we don't want to add special cases in the inference for specific traits.) The function needs to know about it because you can do many more things with a 'static than a 'a (as 'static references can never become dangling).

Re: An alternative introduction to Rust

#92
post #89

Earlier quoted context omitted.

I think namespace qualification syntax and trait bounds make it more confusing ` ::Output: 'a` gives me eye cancer and my intuition is if `P: Neg + 'a` then `P::Output: 'a` is implied (why would it not have that bound if P does?) the Neg trait's Output IS Self (as Neg)! Why is the bound not transitive?

> ` ::Output: 'a` gives me eye cancer and my intuition is if `P: Neg + 'a` then `P::Output: 'a` is implied (why would it not have that bound if P does?) What if the output of the unary minus method was say, a constant 'static? This is a reasonable thing for a function to want to do in general. (Probably not for Neg in particular, but obviously we don't want to add special cases in the inference for specific traits.)…

But it's not, the Output is Self not Self + 'static

Re: An alternative introduction to Rust

#93
post #92

Earlier quoted context omitted.

> ` ::Output: 'a` gives me eye cancer and my intuition is if `P: Neg + 'a` then `P::Output: 'a` is implied (why would it not have that bound if P does?) What if the output of the unary minus method was say, a constant 'static? This is a reasonable thing for a function to want to do in general. (Probably not for Neg in particular, but obviously we don't want to add special cases in the inference for specific traits.)…

But it's not, the Output is Self not Self + 'static

I think you're misunderstanding what Self means in the definition of Neg. The Self is only there so that it is clear which type's "Output" is being referred to. It doesn't establish any type/trait/lifetime relationship between the type of the receiver and the output type. It would be perfectly possible to implement Neg with a 'static output lifetime.

Re: An alternative introduction to Rust

#94
post #92

Earlier quoted context omitted.

But it's not, the Output is Self not Self + 'static

I think you're misunderstanding what Self means in the definition of Neg. The Self is only there so that it is clear which type's "Output" is being referred to. It doesn't establish any type/trait/lifetime relationship between the type of the receiver and the output type. It would be perfectly possible to implement Neg with a 'static output lifetime.

Yeah, I got it, people on IRC helped me understand that it's not casting it as `Neg`, it's casting the type as `Neg` for namespacing purposes
Post reply on HN