Rust Linz, October 2021 - Rust Closures by Rainer Stropek

Поделиться
HTML-код
  • Опубликовано: 28 ноя 2024

Комментарии • 29

  • @robertmullings7481
    @robertmullings7481 3 года назад +18

    Had to add a comment. Rainer, that was a brilliantly conceived and delivered talk. One of the clearest on Rust I have heard so far. Keep up the good work!

  • @kurkdebraine8139
    @kurkdebraine8139 8 месяцев назад

    Mr Stropek you are one of the best exposer i“ve ever heard on the topic. This talk was invaluable for me! Thanks a lot.
    Rust, give this man more talks please. And ty you too.

  • @Roms8313
    @Roms8313 3 года назад +7

    that was just perfect recap, glad you introduced the 2021 features too !

  • @KaneYork
    @KaneYork 3 года назад +3

    Yes, this is essentially how the syntax is done in Ruby! A language famous for being extremely difficult yet still deterministic to parse.

  • @sagnikbhattacharya1202
    @sagnikbhattacharya1202 3 года назад +2

    Great talk, I just have a meme 32:23
    Rainer: You can use disjoint closures in real-world examples.
    Also Rainer: *Literally uses disjoint closures in a fairy tale example*

  • @kaypope1581
    @kaypope1581 2 года назад +2

    Wow, I never thought about FnOnce like case in closure context before. I guess Rust force you to think about all these details and subtle differences. Thanks for the awesome presentation.

  • @thanhtan030t
    @thanhtan030t 5 месяцев назад

    the presentation skill is impressive. thank you, sir!

  • @nirmalyasengupta6883
    @nirmalyasengupta6883 Год назад

    The way you have explained, is quite useful. Coming from the Scala world, I am trying to map my understanding between two languages (and their philosophies). This presentation supplements that very well. Thank you.

  • @luizchagasjardim
    @luizchagasjardim 3 года назад +2

    Great talk. Lambdas are one of the few things where I prefer the C++ version. In C++ it's clearer what's being captured and what kind of capture it's using for each variable.

  • @TinBryn
    @TinBryn 3 года назад +10

    A small correction at 4:46 you said the line "let f: fn add(i32, i32) -> i32 = add;" declares "f" as a function pointer. "f" is actually a function item which is a zero sized type that statically represents a specific function. If you made it mutable and later assigned it to "fn sub(i32, i32) -> i32" this would fail to compile

    • @Dorumin
      @Dorumin 3 года назад +1

      Yeah I knew there was something off about "function pointer", thanks

  • @Galakyllz
    @Galakyllz 2 года назад

    This was very well done. I really appreciate this talk; I definitely learned something.

  • @saaddahmani1870
    @saaddahmani1870 2 года назад

    Great, your explanation is so clear.... thanks.

  • @changtimwu
    @changtimwu 3 года назад +1

    Great talk about rust closures. I have a question irrevalent to Rust. How did you annotate certain area of code in vscode during desktop recording? Is it a featue of your live broadcast software?

  • @func0der
    @func0der 2 года назад

    Thank you very much for this clear explanations. Though I am not very strong in Rust (kind of post-beginner), I was able to follow it. I just have to make me a refresher on concepts like dyn keyword with Traits. But for sure, I can find many videos/blogs explaining this concept.
    Very good video.

  • @LukeAvedon
    @LukeAvedon 2 года назад

    It's that C# guy!!!

  • @theherk
    @theherk 3 года назад +1

    I'm confused by the use of the term closure for all the examples around the 7 minute mark. They seem to be just lambdas or anonymous functions, and they don't close over any values from the environment. They don't use arguments from the surrounding scope, so why are they closures?

  • @johnfunk1815
    @johnfunk1815 2 года назад

    Greats concise explanations.

  • @noyb-yb
    @noyb-yb 2 года назад

    great talk, thank you

  • @jhbonarius
    @jhbonarius 3 года назад +1

    Wow, needing to box the closure which allocates on the heap when you reference an external variable seems heavy! C++ lambda capture by reference seems much more lightweight in comparison

    • @deanroddey2881
      @deanroddey2881 3 года назад +2

      Yeh, that seems odd. I would have thought you could just pass it as 'dyn Fn" without the box. I can't imagine anyone would want to pay that cost for invocation of the kind of trivial to semi-trivial code often done in lambas/closures.
      I would also take exception to his claim that Rust is very explicit. There's a huge amount of magical syntactical sugar in Rust.

    • @trolledwoods377
      @trolledwoods377 3 года назад +3

      You don't need to, you can use &dyn Fn, &mut dyn FnMut, make the closure a generic of the fy ction instead etc... There are lots of options

    • @jhbonarius
      @jhbonarius 3 года назад

      @@trolledwoods377 ok, that's good. But these need to be properly taught. This video is not doing that. It's confusing experienced in programming, but new to Rust.

    • @ChumX100
      @ChumX100 3 года назад +1

      @@jhbonarius I suppose the reason Box is used here instead of bare references is that Box takes ownership of the values it wraps, while references do not, so with references, lifetime annotations would sometimes be necessary and would make the code more difficult to understand.

    • @tsg1zzn
      @tsg1zzn 3 года назад

      I was also surprised to see this, so I tested it. It is possible to pass by reference.
      ```
      fn main() {
      fn add(x: i64, y: i64) -> i64 {
      x + y
      }
      fn calc_and_print(x: i64, y: i64, calcfn: &dyn Fn(i64, i64) -> i64) {
      let result = calcfn(x, y);
      println!("{}", result);
      }
      calc_and_print(1, 2, &add);
      calc_and_print(1, 2, &|x, y| x + y);
      let z = 5;
      calc_and_print(1, 2, &|x, y| x + y + z);
      }
      ```

  • @jhbonarius
    @jhbonarius 3 года назад

    "You can remove the parentheses and make it even nicer"
    ...i wish everybody thought like that
    I had a discussion with my tech lead (C#) and proposed thing like that. He hated it. He still seems to have problems with moving from VB to C#, and would even prefer to use "end function" and such over parentheses...

  • @emvdl
    @emvdl 3 года назад

    Thanks

  • @azizul_islam
    @azizul_islam Год назад

    font size too small :(

  • @quickD11
    @quickD11 2 года назад

    Great Explanation, however I'd like to leave a comment: at ruclips.net/video/bgZa9VRBhYU/видео.html you do not actually need to do boxing, accept `&dyn Fn(i32, i32) -> i32` instead. In such a case, explicit lifetimes can also be dropped.