3 ms·
What does `type Output = Self;` for the `std::ops::Neg` trait mean? It wasn't explained on the page.
by zimbatm 7y ago
What does `type Output = Self;` for the `std::ops::Neg` trait mean? It wasn't explained on the page.
- Lev1a 7y agoIIRC that's called "associated type" and is mostly used for shortening the function declaration inside the trait through using e.g. "Self::Output". E.g. the definition of the real std::ops::Neg trait: https://doc.rust-lang.org/std/ops/trait.Neg.html https://doc.rust-lang.org/std/ops/trait.Neg.html
- steveklabnik 7y agoIt’s not about shortening things, it’s actually about semantics! Choosing to make something have a type parameter vs an associated type depends on what you’re trying to accomplish.