From d5b1d449e5f4615fa0c4c12ca8ff0da66eb2819f Mon Sep 17 00:00:00 2001 From: brent s Date: Tue, 27 Jul 2021 22:30:10 -0400 Subject: [PATCH] adding small usage note for bitmasks --- types/bitmasks.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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)