github.com/antihax/goesi@v0.0.0-20240126031043-6c54d0cb7f95/optional/uint16.go (about)

     1  package optional
     2  
     3  type Uint16 struct {
     4  	isSet bool
     5  	value uint16
     6  }
     7  
     8  func NewUint16(value uint16) Uint16 {
     9  	return Uint16{
    10  		true,
    11  		value,
    12  	}
    13  }
    14  
    15  // EmptyUint16 returns a new Uint16 that does not have a value set.
    16  func EmptyUint16() Uint16 {
    17  	return Uint16{
    18  		false,
    19  		0,
    20  	}
    21  }
    22  
    23  func (i Uint16) IsSet() bool {
    24  	return i.isSet
    25  }
    26  
    27  func (i Uint16) Value() uint16 {
    28  	return i.value
    29  }
    30  
    31  func (i Uint16) Default(defaultValue uint16) uint16 {
    32  	if i.isSet {
    33  		return i.value
    34  	}
    35  	return defaultValue
    36  }