RustConf 2023 - How Powerful is Const

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

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

  • @knolljo
    @knolljo 10 месяцев назад +25

    Const generics look very interesting to me, especially since i like the typestate pattern and const generics look like they could be an easy way to implement it

    • @dmitriidemenev5258
      @dmitriidemenev5258 10 месяцев назад

      I've implemented yet not published the crate called ctoption (compile-time option). They allow to do that.

  • @RootsterAnon
    @RootsterAnon 10 месяцев назад +5

    👏👏👏👏 nice presentation, really enjoyed the deep dive into consts and what they can offer at certain depth level. I mostly use it very basically but now I see that there are more stuff to learn about them.

  • @9SMTM6
    @9SMTM6 10 месяцев назад +1

    Sure the AppendNull struct works correctly? I don't know whether alignment could not mess that up, I sure am not certain that a single u8 is never handled differently with alignment from a corresponding slice.
    I would certainly try to test/ assert that the resulting byte pattern for at least some tests (up to the total size of 64 bit) is the same as with manually adding a terminating null.
    Alternatively, I believe using repr(packed) provides stronger guarantees.

    • @Baptistetriple0
      @Baptistetriple0 10 месяцев назад +6

      if you look at the book on data layout, the repr(C) guarantees that the alignement is 1 with the AppendNull struct as it is aligned with the biggest field alignement (so 1 here as [T] has the same alignement as T), and the algorithm that is used to calculate fields offset also guarantees that when all fields have the same alignement there is no padding. repr(C) also guarantees field ordering, something repr(packed) nor repr(Rust) guarantees. Sure you could use repr(C, packed) and be absolutely sure, but it is already well defined with just repr(C).

  • @Babakinha
    @Babakinha 10 месяцев назад +5

    16:18 Meta programming flashbacks (。o_o。)""

  • @jocketf3083
    @jocketf3083 10 месяцев назад

    Awesome!

  • @davidjaz7663
    @davidjaz7663 10 месяцев назад +3

    The people yearn for dependent types…

    • @sayaks12
      @sayaks12 10 месяцев назад

      how would that even work when rust is a completely type erased language?

  • @KyleSmithNH
    @KyleSmithNH 10 месяцев назад

    Could the usize example be solved with a cfg directive?

    • @nvzqz
      @nvzqz 10 месяцев назад

      Yes but you would need to handle each pointer width. This approach works with a single statement using a bool condition, which is simpler in some regards.