RustConf 2023 - How Powerful is Const

Поділитися
Вставка
  • Опубліковано 25 гру 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.

  • @Babakinha
    @Babakinha 10 місяців тому +5

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

  • @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).

  • @jocketf3083
    @jocketf3083 10 місяців тому

    Awesome!

  • @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.

  • @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?