Skip to main content

dpp_digital_link/digital_link/
ai.rs

1//! GS1 Application Identifier (AI) type table for Digital Link URI paths.
2
3/// Role of a GS1 Application Identifier within a Digital Link URI path.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum AiRole {
6    PrimaryKey,
7    Qualifier,
8    DataAttribute,
9}
10
11pub struct AiDescriptor {
12    pub code: &'static str,
13    pub role: AiRole,
14    pub title: &'static str,
15    pub max_len: usize,
16    /// Canonical qualifier order within the path; `None` for PrimaryKey.
17    pub qualifier_order: Option<u8>,
18}
19
20/// Static table of recognised GS1 Application Identifiers for DL URI paths.
21pub const AI_TABLE: &[AiDescriptor] = &[
22    AiDescriptor {
23        code: "01",
24        role: AiRole::PrimaryKey,
25        title: "GTIN",
26        max_len: 14,
27        qualifier_order: None,
28    },
29    AiDescriptor {
30        code: "22",
31        role: AiRole::Qualifier,
32        title: "Consumer Product Variant",
33        max_len: 20,
34        qualifier_order: Some(1),
35    },
36    AiDescriptor {
37        code: "10",
38        role: AiRole::Qualifier,
39        title: "Batch/Lot Number",
40        max_len: 20,
41        qualifier_order: Some(2),
42    },
43    AiDescriptor {
44        code: "21",
45        role: AiRole::Qualifier,
46        title: "Serial Number",
47        max_len: 20,
48        qualifier_order: Some(3),
49    },
50    AiDescriptor {
51        code: "235",
52        role: AiRole::Qualifier,
53        title: "Third-Party Controlled Serial",
54        max_len: 28,
55        qualifier_order: Some(4),
56    },
57];
58
59/// Look up a descriptor by AI code, returning `None` for unknown codes.
60pub fn ai_descriptor(code: &str) -> Option<&'static AiDescriptor> {
61    AI_TABLE.iter().find(|d| d.code == code)
62}