mirror of
https://github.com/kopia/kopia.git
synced 2026-03-29 03:21:32 -04:00
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package policy
|
|
|
|
// OptionalBool provides convenience methods for manipulating optional booleans.
|
|
type OptionalBool bool
|
|
|
|
// OrDefault returns the value of the boolean or provided default if it's nil.
|
|
func (b *OptionalBool) OrDefault(def bool) bool {
|
|
if b == nil {
|
|
return def
|
|
}
|
|
|
|
return bool(*b)
|
|
}
|
|
|
|
// NewOptionalBool provides an OptionalBool pointer.
|
|
func NewOptionalBool(b OptionalBool) *OptionalBool {
|
|
return &b
|
|
}
|
|
|
|
// OptionalInt provides convenience methods for manipulating optional integers.
|
|
type OptionalInt int
|
|
|
|
// OrDefault returns the value of the integer or provided default if it's nil.
|
|
func (b *OptionalInt) OrDefault(def int) int {
|
|
if b == nil {
|
|
return def
|
|
}
|
|
|
|
return int(*b)
|
|
}
|
|
|
|
func newOptionalInt(b OptionalInt) *OptionalInt {
|
|
return &b
|
|
}
|
|
|
|
// OptionalInt64 provides convenience methods for manipulating optional integers.
|
|
type OptionalInt64 int64
|
|
|
|
// OrDefault returns the value of the integer or provided default if it's nil.
|
|
func (b *OptionalInt64) OrDefault(def int64) int64 {
|
|
if b == nil {
|
|
return def
|
|
}
|
|
|
|
return int64(*b)
|
|
}
|
|
|
|
func newOptionalInt64(b OptionalInt64) *OptionalInt64 {
|
|
return &b
|
|
}
|