Rust: “Explain GATs Like I'm 5 Years Old”
old.reddit.com
Rust: “Explain GATs Like I'm 5 Years Old”
1–10 of 193 posts
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#2Re: Rust: “Explain GATs Like I'm 5 Years Old”
#3Re: Rust: “Explain GATs Like I'm 5 Years Old”
#4As a beginner (having finished the book and not much more) the example in the top comment is very difficult to parse and hold in my head. At a glance I have no idea what we're doing and why.
trait X {
type Y;
}
You couldn't express "a thing that contains another thing" in one of those type expressions before, and also use the contained type. It's needed for Mappable, because it's an abstraction over the concept of modifying a value inside a container.IMO the implementation that they have is a bit obtuse, but I don't know if you can fit something better in this language.
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#5Re: Rust: “Explain GATs Like I'm 5 Years Old”
#6No doubt they'll needlessly spread to code that doesn't require them - happened already with async and that is much, much simpler concept (than one of the most complex things, GATs).
It's something that you naturally try to write when you don't know it's not supported, rather than an additional thing to learn.
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#7As a beginner (having finished the book and not much more) the example in the top comment is very difficult to parse and hold in my head. At a glance I have no idea what we're doing and why.
The example in the top comment allows you to implement what it means for a type to "have a `map` function". So it doesn't get rid of the duplicated effort on the "supply side" - we still have to implement the `Mappable` trait for each of `Result` and `Option` individually - but it allows the consumer to not care whether it's got an `Option` or a `Result`, by using only the `Mappable` trait instead. That is newly possible because the GAT feature allows the definition of a `Mappable` trait which contains fresh generics, and `map` is inherently a generic function.
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#8https://blog.rust-lang.org/2022/10/28/gats-stabilization.htm...
Re: Rust: “Explain GATs Like I'm 5 Years Old”
#9No doubt they'll needlessly spread to code that doesn't require them - happened already with async and that is much, much simpler concept (than one of the most complex things, GATs).
If there’s anything to worry about then that may be compile times of complex codebases. I haven’t measured anything but just as a rule of thumb more generic code means longer compile times in Rust-land.