#I can't figure how to use this bitflags
1 messages · Page 1 of 1 (latest)
I need to check if "Once" is true
pub const FlagsInt = u32;
pub fn FlagsMixin(comptime FlagType: type) type {
comptime assert(@sizeOf(FlagType) == 4);
return struct {
pub fn toInt(self: FlagType) FlagsInt {
return @as(FlagsInt, @bitCast(self));
}
pub fn fromInt(value: FlagsInt) FlagType {
return @as(FlagType, @bitCast(value));
}
pub fn with(a: FlagType, b: FlagType) FlagType {
return fromInt(toInt(a) | toInt(b));
}
pub fn only(a: FlagType, b: FlagType) FlagType {
return fromInt(toInt(a) & toInt(b));
}
pub fn without(a: FlagType, b: FlagType) FlagType {
return fromInt(toInt(a) & ~toInt(b));
}
pub fn hasAllSet(a: FlagType, b: FlagType) bool {
return (toInt(a) & toInt(b)) == toInt(b);
}
pub fn hasAnySet(a: FlagType, b: FlagType) bool {
return (toInt(a) & toInt(b)) != 0;
}
pub fn isEmpty(a: FlagType) bool {
return toInt(a) == 0;
}
pub fn eql(a: FlagType, b: FlagType) bool {
return toInt(a) == toInt(b);
}
};
}
why is it so unnecessarily complicated
the library author just expects me to know how to use this