r/ProgrammingLanguages • u/ExplodingStrawHat • Apr 29 '26
Blessed Syntax and Ergonomics
https://www.gingerbill.org/article/2026/04/29/blessed-syntax-and-ergonomics/(not my article, but thought y'all might find it interesting)
33
Upvotes
View all comments
Show parent comment
4
u/AhoyISki Apr 29 '26
Yeah... I also ran into some issues in regards to implementing
Indexfor my structs as well.Although there is a sort of workaround in some situations. You can take advantage of wide pointers, something like
&str, which not only encodes a memory address, but also some data, specifically the length of the string.In my case, I wanted a
&str-like type, but for aGapBuffer. I did that by giving a reference to the gap buffer on the address part of the pointer, then encoding two 32 bit numbers on the "length" part of the pointer, which is normally 64 bits (on most systems).Those two u32s would point to the start and length of the region on the gap buffer, so all I had to do was transmute in and out of a
[u32; 2], which was used as the length part of the pointer, for a total of 128 bits.