You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe this is actually distinct from #7921 which is only suggesting an API tweak: to remove the indirection of TraitFn in favor of passing all args up front. But there's still only one type argument, the type being tested against the trait.
This proposal instead is suggesting added functionality - the ability to assert on the type of a struct field decl. There would be two type arguments involved here:
The type that the given decl/field should have
The type being tested against the trait.
I would like to be able to do this. After all, if you're expecting a next(_: *@This()) ?T but the type has a next(_: usize) usize that's obviously going to cause problems.
However, if we take this step, further things will pop up. How would you specify the type of a method with a Self argument?
So, I think this could be important functionality, but needs some further design work to figure out how to specify more complex traits. However, it could be possible that the interface complexity isn't worth it compared to more manual asserts against @typeInfo
Motivation
As of now
std.meta.trait.hasFn
andstd.meta.trait.hasField
are matching on members identifiers alone.This is not very usefull to express shared behavior.
Proposal
Match on members signatures instead.
hasFn(comptime name: []const u8)
in favor of a more generichasDecl(comptime name: []const u8, comptime T: type)
hasField(comptime name: []const u8)
tohasField(comptime name: []const u8, comptime T: type)
Usage
Related issues
#3839 (naming coherence)
#1268 (use case)
The text was updated successfully, but these errors were encountered: