go_goutils/bitmask/doc.go

54 lines
883 B
Go
Raw Normal View History

/*
Package bitmask handles a flag-like opt/bitmask system.
See https://yourbasic.org/golang/bitmask-flag-set-clear/ for more information.
To use this, set constants like thus:
package main
import (
"r00t2.io/goutils/bitmask"
)
const OPTNONE bitmask.MaskBit = 0
const (
OPT1 bitmask.MaskBit = 1 << iota
OPT2
OPT3
// ...
)
var MyMask *bitmask.MaskBit
func main() {
MyMask = bitmask.NewMaskBit()
MyMask.AddFlag(OPT1)
MyMask.AddFlag(OPT3)
_ = MyMask
}
This would return true:
MyMask.HasFlag(OPT1)
As would this:
MyMask.HasFlag(OPT3)
But this would return false:
MyMask.HasFlag(OPT2)
If you need something with more flexibility (as always, at the cost of complexity),
you may be interested in one of the following libraries:
. github.com/alvaroloes/enumer
. github.com/abice/go-enum
. github.com/jeffreyrichter/enum/enum
*/
package bitmask