Closed
Description
Motivation
As of now std.meta.trait.hasFn
and std.meta.trait.hasField
are matching on members identifiers alone.
This is not very usefull to express shared behavior.
Proposal
Match on members signatures instead.
- Remove
hasFn(comptime name: []const u8)
in favor of a more generichasDecl(comptime name: []const u8, comptime T: type)
- Change
hasField(comptime name: []const u8)
tohasField(comptime name: []const u8, comptime T: type)
Usage
const trait = @import("std").meta.trait;
const isMyTrait = trait.multiTrait(.{
trait.hasField("my_field", u8),
trait.hasDecl("my_const", []const u8),
trait.hasDecl("myFn", fn(bool, u8) f64),
});