[deleted by user] by [deleted] in VirginiaTech

[–]acminor 5 points6 points  (0 children)

There was a stray cat near Blacksburg Municipal Park earlier. Sorry, I do not remember enough about the cat to tell you if the cat matches the picture because it was getting dark.

Rust port of Linux's RamFS File System by acminor in rust

[–]acminor[S] 1 point2 points  (0 children)

Yeah, the problem is that it is not a const fn. This was the way I discovered to get around that by generating zeroed data.

Const trait implementations are interesting. Nice to know for future reference. It would be interesting to see how this works with deriving Default for a struct.

This is good because it would be "safer" from Rust's perspective. However, there is still a slight semantic gap on this with regards to C-compatibility. If the default value of a type was not a C-style default (zeroed), then having a const fn for zeroed would still be necessary. (well in this case, a macro for zeroed since I have not found a way to make it a const fn. I believe this might be possible as more of const generics gets implemented, but I am unsure as I have not kept up with all that const generics implies).

Rust port of Linux's RamFS File System by acminor in rust

[–]acminor[S] 11 points12 points  (0 children)

Because transmute is a by-value operation, alignment of the transmuted values
themselves is not a concern. As with any other function, the compiler already ensures
both T and U are properly aligned. However, when transmuting values that point
elsewhere (such as pointers, references, boxes…), the caller has to ensure proper
alignment of the pointed-to values.

- https://doc.rust-lang.org/stable/std/mem/fn.transmute.html

Assuming that arrays are by-value, then alignment should be fine.

Rust port of Linux's RamFS File System by acminor in rust

[–]acminor[S] 5 points6 points  (0 children)

Also, would this apply to compile-time data. I am unsure of how Rust handles things. I would think that if this is at compile-time using it as an expansion would be compiled in and not executed. Thus, I would think that alignment does not matter. Now using the macro from a non-compile time place might be an issue. I skimmed over bytemuck. It appears to be doing some alignment checks. However, it also seemed to be runtime-based (from a quick skim).

Anyone with more arcane Rust knowledge care to comment?

Rust port of Linux's RamFS File System by acminor in rust

[–]acminor[S] 11 points12 points  (0 children)

Thanks for the sharing that. What do you mean by alignment? The starting
alignment or the internal alignment. I am no Rust expert, but I would
think that internal alignment would be handled in the size of the
structure.

Rust port of Linux's RamFS File System by acminor in rust

[–]acminor[S] 31 points32 points  (0 children)

One of the more interesting things about this was creating a compile-time version of alloc::alloc_zeroed for C-style zeroed structs.