gl_gtin/gtin_types
Shared public GTIN types.
This module defines the public GtinError and GtinFormat types in a
location that does NOT import the root gl_gtin facade. Both the facade
(gl_gtin) and the sub-modules that already work in GtinError
(e.g. gl_gtin/upc) import these types from here, which breaks what would
otherwise be an import cycle (gl_gtin → gl_gtin/upc → gl_gtin).
The root gl_gtin module re-exports these types via type aliases
(gl_gtin.GtinError, gl_gtin.GtinFormat) so the public type names are
unchanged. The variant constructors are owned by this module, so consumers
import them from here, e.g. import gl_gtin/gtin_types.{Gtin13, InvalidFormat}.
Types
Errors that can occur when working with GTIN codes.
pub type GtinError {
InvalidLength(got: Int)
InvalidCheckDigit
InvalidCharacters
NoGs1PrefixFound
InvalidFormat
InvalidKeyFormat
}
Constructors
-
InvalidLength(got: Int)Input has wrong number of digits. Includes the actual length provided.
-
InvalidCheckDigitCheck digit does not match the calculated value.
-
InvalidCharactersInput contains non-numeric characters.
-
NoGs1PrefixFoundGS1 prefix not found in the database.
-
InvalidFormatOperation not applicable to this GTIN format.
-
InvalidKeyFormatKey-specific structural failure: a GS1 key (e.g. a variable-serial
Grai/Giai) whose length and check digit are plausible but whose component structure is malformed. Distinct fromInvalidFormat, which remains reserved for GTIN format-conversion failures.
Supported GTIN formats based on digit count.
pub type GtinFormat {
Gtin8
Gtin12
Gtin13
Gtin14
}
Constructors
-
Gtin88-digit GTIN format, used for small packages outside North America
-
Gtin1212-digit GTIN format (UPC-A), primarily used in North America
-
Gtin1313-digit GTIN format (EAN-13), used internationally
-
Gtin1414-digit GTIN format (ITF-14), used for trade items at various packaging levels