-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
proposalA *potential* improvementA *potential* improvement
Description
Sometimes I write helper functions that need access to specific components of the ECS storage. These functions might be used from different systems, with different storage subsets. It would be nice, if there was some sort of compile time checked casting between different subsets, maybe like this:
const Storage = ecez.CreateStorage(.{
Position,
Velocity,
});
const All = Storage.Subset(.{
*Position,
*Velocity,
});
const PosRead = Storage.Subset(.{Position});
var storage = Storage.init(alloc);
var all = All{ .storage = &storage };
var pos_read = PosRead{ .storage = &storage };
// casting
const all_cast = pos_read.cast(All); // -> Not allowed, compile error
const pos_read_cast = all.cast(PosRead); // -> Allowed, returns *PosRead
Currently, I am simply using @ptrCast
. It works, but there are no checks. If this could be done automatically by coercion somehow, it would be magical! But I don't think that is currently possible with the zig type system.
Metadata
Metadata
Assignees
Labels
proposalA *potential* improvementA *potential* improvement