Documentation ¶
Index ¶
- Variables
- type Length
- type LengthUnits
- func (enum LengthUnits) EnsureValid() LengthUnits
- func (enum LengthUnits) Format(length Length) string
- func (enum LengthUnits) Key() string
- func (enum LengthUnits) MarshalText() (text []byte, err error)
- func (enum LengthUnits) String() string
- func (enum LengthUnits) ToInches(length fxp.Int) fxp.Int
- func (enum *LengthUnits) UnmarshalText(text []byte) error
- type Weight
- type WeightUnits
- func (enum WeightUnits) EnsureValid() WeightUnits
- func (enum WeightUnits) Format(weight Weight) string
- func (enum WeightUnits) Key() string
- func (enum WeightUnits) MarshalText() (text []byte, err error)
- func (enum WeightUnits) String() string
- func (enum WeightUnits) ToPounds(weight fxp.Int) fxp.Int
- func (enum *WeightUnits) UnmarshalText(text []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( // AllLengthUnits holds all possible values. AllLengthUnits = []LengthUnits{ FeetAndInches, Inch, Feet, Yard, Mile, Centimeter, Kilometer, Meter, } )
var ( // AllWeightUnits holds all possible values. AllWeightUnits = []WeightUnits{ Pound, PoundAlt, Ounce, Ton, TonAlt, Kilogram, Gram, } )
Functions ¶
This section is empty.
Types ¶
type Length ¶
Length contains a fixed-point value in inches. Conversions to/from metric are done using the simplified Length metric conversion of 1 yd = 1 meter. For consistency, all metric lengths are converted to meters, then to yards, rather than the variations at different lengths that the Length rules suggest.
func LengthFromInteger ¶
func LengthFromInteger[T constraints.Integer](value T, unit LengthUnits) Length
LengthFromInteger creates a new Length.
func LengthFromString ¶
func LengthFromString(text string, defaultUnits LengthUnits) (Length, error)
LengthFromString creates a new Length. May have any of the known Units suffixes, a feet and inches format (e.g. 6'2"), or no notation at all, in which case defaultUnits is used.
func LengthFromStringForced ¶
func LengthFromStringForced(text string, defaultUnits LengthUnits) Length
LengthFromStringForced creates a new Length. May have any of the known Units suffixes, a feet and inches format (e.g. 6'2"), or no notation at all, in which case defaultUnits is used.
func (Length) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Length) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type LengthUnits ¶
type LengthUnits byte
LengthUnits holds the length unit type. Note that conversions to/from metric are done using the simplified GURPS metric conversion of 1 yd = 1 meter. For consistency, all metric lengths are converted to meters, then to yards, rather than the variations at different lengths that the GURPS rules suggest.
const ( FeetAndInches LengthUnits = iota Inch Feet Yard Mile Centimeter Kilometer Meter LastLengthUnits = Meter )
Possible values.
func ExtractLengthUnits ¶
func ExtractLengthUnits(str string) LengthUnits
ExtractLengthUnits extracts the value from a string.
func (LengthUnits) EnsureValid ¶
func (enum LengthUnits) EnsureValid() LengthUnits
EnsureValid ensures this is of a known value.
func (LengthUnits) Format ¶
func (enum LengthUnits) Format(length Length) string
Format the length for this LengthUnits.
func (LengthUnits) Key ¶
func (enum LengthUnits) Key() string
Key returns the key used in serialization.
func (LengthUnits) MarshalText ¶
func (enum LengthUnits) MarshalText() (text []byte, err error)
MarshalText implements the encoding.TextMarshaler interface.
func (LengthUnits) ToInches ¶
func (enum LengthUnits) ToInches(length fxp.Int) fxp.Int
ToInches converts the length in this LengthUnits to inches.
func (*LengthUnits) UnmarshalText ¶
func (enum *LengthUnits) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Weight ¶
Weight contains a fixed-point value in pounds.
func WeightFromInteger ¶
func WeightFromInteger[T constraints.Integer](value T, unit WeightUnits) Weight
WeightFromInteger creates a new Weight.
func WeightFromString ¶
func WeightFromString(text string, defaultUnits WeightUnits) (Weight, error)
WeightFromString creates a new Weight. May have any of the known Weight suffixes or no notation at all, in which case defaultUnits is used.
func WeightFromStringForced ¶
func WeightFromStringForced(text string, defaultUnits WeightUnits) Weight
WeightFromStringForced creates a new Weight. May have any of the known Weight suffixes or no notation at all, in which case defaultUnits is used.
func (Weight) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Weight) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type WeightUnits ¶
type WeightUnits byte
WeightUnits holds the weight unit type. Note that conversions to/from metric are done using the simplified GURPS metric conversion of 1 lb = 0.5kg. For consistency, all metric weights are converted to kilograms, then to pounds, rather than the variations at different weights that the GURPS rules suggest.
const ( Pound WeightUnits = iota PoundAlt Ounce Ton TonAlt Kilogram Gram LastWeightUnits = Gram )
Possible values.
func ExtractWeightUnits ¶
func ExtractWeightUnits(str string) WeightUnits
ExtractWeightUnits extracts the value from a string.
func TrailingWeightUnitsFromString ¶
func TrailingWeightUnitsFromString(s string, defUnits WeightUnits) WeightUnits
TrailingWeightUnitsFromString extracts a trailing WeightUnits from a string.
func (WeightUnits) EnsureValid ¶
func (enum WeightUnits) EnsureValid() WeightUnits
EnsureValid ensures this is of a known value.
func (WeightUnits) Format ¶
func (enum WeightUnits) Format(weight Weight) string
Format the weight for this WeightUnits.
func (WeightUnits) Key ¶
func (enum WeightUnits) Key() string
Key returns the key used in serialization.
func (WeightUnits) MarshalText ¶
func (enum WeightUnits) MarshalText() (text []byte, err error)
MarshalText implements the encoding.TextMarshaler interface.
func (WeightUnits) ToPounds ¶
func (enum WeightUnits) ToPounds(weight fxp.Int) fxp.Int
ToPounds the weight for this WeightUnits.
func (*WeightUnits) UnmarshalText ¶
func (enum *WeightUnits) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.