gl_gtin/gs1_prefix

GS1 prefix lookup module for GTIN codes.

Provides country/region lookup based on GS1 prefix codes. Checks 3-digit prefixes first, then 2-digit prefixes.

Types

Error type for prefix lookup operations

pub type PrefixError {
  NoGs1PrefixFound
}

Constructors

  • NoGs1PrefixFound

Values

pub fn lookup(code: String) -> Result(String, PrefixError)

Look up the country of origin from a GTIN code’s GS1 prefix.

Checks the first 2-3 digits of the GTIN against the GS1 prefix database. Checks 3-digit prefixes first, then 2-digit prefixes.

Arguments

  • code - GTIN code string

Returns

Ok(country) if a prefix is found, Error(NoGs1PrefixFound) otherwise.

Examples

lookup("6291041500213")
// -> Ok("GS1 Emirates")

lookup("012345678905")
// -> Ok("GS1 US")

lookup("999999999999")
// -> Error(NoGs1PrefixFound)
Search Document