diff --git a/types/bitmasks.go b/types/bitmasks.go index f5888b7..e70d4e3 100644 --- a/types/bitmasks.go +++ b/types/bitmasks.go @@ -1,5 +1,36 @@ package types +/* + See https://yourbasic.org/golang/bitmask-flag-set-clear/ for more information. + To use this, set constants like thus: + + const ( + OPT1 types.MaskBit = 1 << iota + OPT2 + OPT3 + // ... + ) + + type Object struct { + Opts BitMask + } + + o := Object{ + BitMask: uint8(0) + } + + o.AddFlag(OPT1) + o.AddFlag(OPT3) + + + This would return true: + o.HasFlag(OPT1) + As would this: + o.HasFlag(OPT3) + But this would return false: + o.HasFlag(OPT2) + +*/ type BitMask interface { HasFlag(bit MaskBit) bool AddFlag(bit MaskBit)