Impl Trait aka Look ma’, no generics! by Jon Gjengset

preview_player
Показать описание
#rust #rustlang #programming
Hosted at DIKU (University of Copenhagen) on the 28th of September 2023

0:00:00 Introduction
0:01:02 Return position impl Trait
0:14:41 Argument position impl Trait
0:17:04 Associated type impl Trait
0:23:05 Type alias impl Trait
0:28:50 Return position impl Trait in traits
0:33:41 Asynchronous functions in traits
0:37:09 Q&A
0:37:41 Q: Should I push back on adopting impl Trait?
0:40:15 Q: Existentials in argument position
0:41:40 Q: Will +'a in return position become an error?
0:43:14 Q: Can the hidden type vary by generic params?
0:44:24 Q: What does +'a actually mean?
0:45:11 Q: Why does +'a mostly work?
0:45:57 Q: Can I just put +'static?
0:47:16 Q: Do we need inverse syntax for +'a?
0:48:02 Q: Will the edition upgrade require code change?
0:49:03 Q: Can two async blocks map to one hidden type?
0:51:49 Q: What happens if there is no defining use?
0:52:29 Q: Will ambiguous defining uses "just work"?
0:54:15 Q: How can fn eat take an existential type?
0:57:04 Q: Can I use existential types in let?
0:58:22 Q: Auto-traits and backwards compatibility
0:59:16 Q: What if we replace Self::IntoIter with impl?
1:00:30 Q: Is taking an existential as an argument bad?
1:01:21 Q: Why is this hard for IDEs?
1:02:32 Q: Interaction with self-defined auto traits
1:05:50 Q: Will you be signing books for beers?
1:06:12 Q: Is the counter you keep for signed or sold books?
1:06:47 Q: I currently write return position impl trait and I often have to write +'a, is that wrong?
Рекомендации по теме
Комментарии
Автор

Jon kindly reached out and let us know of some good news!
The RFC for the new capture rules for the 2024 edition has now been accepted!

copenhagenrustcommunity
Автор

Every Jon Gjengset lecture is a wonderful new experience! Thanks for uploading! 🥰

Onkoe
Автор

A phenomenal educator, my Rust and even general CS skills have grown immensely since discovering Jon

worldboy
Автор

I'd just like to say thank you for the `Captures` trick. Today was the second time I've come back to this video to use it solve my lifetime issues.

juchemz
Автор

I love that Rust keeps having embedded users in mind. I think it’s by far the best area for Rust to shine, even if it’s not a popular one.

theondono
Автор

A slight nitpick for 15:00 (argument impl Trait):
This can still be viewed as an example of an existential type because (exists a. a) -> b is the same as forall a. a -> b (using haskell notation).
If you represents exists with a dependent pair this can be viewed as dependent currying: (a: Type, a) -> b same as (a : Type) -> a -> b.
So imo return and argument position impl Trait are consistent.

antarctic
Автор

Jon is a great teacher.
I wonder if I have some kind of eye cancer or if he has it😬. Gray code on purple background is among the hardest to read I have encountered so far.

gzoechi
Автор

7:45 That compiler gets to peek into `impl Trait` at return position to discovered Send + Unpin seems like a mistake, however expedient.

G
Автор

@22:30 It's a little odd to me that we don't just that it behaves like a return position impl trait—i.e., that there must be some single type which satisfies this that the compiler knows but you're not explicitly specifying. Like, the argument to eat is not "an impl Trait type", it's just an associated type for the trait—which must be a single, specific type—which happens to be defined opaquely. Thus, the function just knows that it's some kind of Iterator<Item = u32> and so that's all you can do with it in eat.

yaksher
Автор

Rust is blazing as fast as possible the path to being as complex as C++

Hector-bjls
Автор

For lifetimes I think Rust would be well served by separating lifetimes from types, like Ocaml did. That is, the lifetime should not be part of the type of a variable like it is now, which forces invasive code changes when a lifetime specification is added.

headlibrarian
Автор

I don't understand the need for a single defining use with #[defines]. Wouldn't all uses need to be compatible, so any one could be taken as the defining use?

juchemz