Possible to cast between arbitrary types? (Non-pointers)


I’m not even sure this makes good sense but I was thinking about this question:

Is it possible to cast between non-pointer types (excluding the int, float, enum style casting).

And to be clear I don’t mean casting between pointers and what not just somehow casting between structs?

An example would be if you have a struct (custom) and you want to cast into another struct with a different layout and if we assume matching alignment and padding can this be done?

You can use @bitCast to reinterpret/cast packed and extern structs to other types of the same size. You can’t @bitCast regular structs, because they have an undefined memory layout.