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

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 พ.ย. 2024

ความคิดเห็น • 24

  • @copenhagenrustcommunity
    @copenhagenrustcommunity  ปีที่แล้ว +14

    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!
    rust-lang.github.io/rfcs/3498-lifetime-capture-rules-2024.html

  • @Onkoe
    @Onkoe ปีที่แล้ว +72

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

  • @worldboy89
    @worldboy89 10 หลายเดือนก่อน +7

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

  • @juchemz
    @juchemz 10 หลายเดือนก่อน +2

    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.

  • @theondono
    @theondono ปีที่แล้ว +20

    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.

    • @meowsqueak
      @meowsqueak 8 หลายเดือนก่อน +1

      I wish RustRover had embedded developers in mind, also.

    • @sortof3337
      @sortof3337 4 หลายเดือนก่อน

      @@meowsqueak ha ha ha. i switched to zed and now I am happy though features are still lacking for iot.

  • @antarctic214
    @antarctic214 ปีที่แล้ว +12

    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.

  • @gzoechi
    @gzoechi 10 หลายเดือนก่อน +1

    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.

  • @G11713
    @G11713 6 วันที่ผ่านมา

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

  • @Hector-bj3ls
    @Hector-bj3ls 6 หลายเดือนก่อน +2

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

    • @tokoucin
      @tokoucin 6 หลายเดือนก่อน

      at least in c++ you can still choose to not.

  • @yaksher
    @yaksher ปีที่แล้ว +3

    @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 and so that's all you can do with it in eat.

    • @bluk
      @bluk ปีที่แล้ว +4

      From the public viewpoint, that's correct, but in the function implementation, you may want to call functions on your specific known type. For instance, the real hidden type returned in the "into_iter" method could also implement DoubleEndedIterator for Odd's ExcessiveIntoIterator trait implementation. Because you are guaranteed the type returned from into_iter() is the same exact type passed into eat, you can now use DoubleEndedIterator in eat(). This does not require that other trait implementations would need to implement DoubleEndedIterator. If you did not care about that eat() is using the same exact type returned from into_iter(), you could of course, use a generic or non-associated impl Trait parameter instead.

  • @ScienceMinisterZero
    @ScienceMinisterZero ปีที่แล้ว +4

    This guy is a singleton type.

  • @headlibrarian1996
    @headlibrarian1996 4 หลายเดือนก่อน +1

    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.

  • @renatoborgogni2534
    @renatoborgogni2534 ปีที่แล้ว +1

    Thank you

  • @odilf_
    @odilf_ ปีที่แล้ว

    Amazing talk

  • @juchemz
    @juchemz ปีที่แล้ว +2

    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?

    • @SimonBuchanNz
      @SimonBuchanNz ปีที่แล้ว

      Only at the source level. When actually compiling the hidden type determines things like the size, trait implementation function addresses, etc.
      Essentially the difference between static and dynamic polymorphism (impl and dyn)

    • @gamekiller0123
      @gamekiller0123 ปีที่แล้ว

      ​@@SimonBuchanNz The hidden type matters, yes. The point is that for there to exist a defining use it has to actually define a single type that fits. If two potential defining uses disagree it should be a compiler error, and if they don't then we can use that type.

    • @gamekiller0123
      @gamekiller0123 ปีที่แล้ว

      I think the issue is once you start getting inference. You can easily set up a situation where the type of one integer affects the type of another, which might not be intended.
      You might be able to set this up in a way where this works in both directions to give different results.
      Still, it seems to me like this could be handled by allowing multiple defining uses *if they agree* and instead allow a use to opt out of being defining.

  • @mcpecommander5327
    @mcpecommander5327 ปีที่แล้ว

    Where’s the slides?