exiftool_rs/tag.rs
1use crate::value::Value;
2
3/// Identifies the metadata group hierarchy (mirrors ExifTool's Group0/Group1/Group2).
4#[derive(Debug, Clone, PartialEq, Eq, Hash)]
5pub struct TagGroup {
6 /// Family 0: Information type (EXIF, IPTC, XMP, ICC_Profile, etc.)
7 pub family0: String,
8 /// Family 1: Specific location (IFD0, ExifIFD, GPS, XMP-dc, etc.)
9 pub family1: String,
10 /// Family 2: Category (Image, Camera, Location, Time, Author, etc.)
11 pub family2: String,
12}
13
14/// A resolved metadata tag with its value and metadata.
15#[derive(Debug, Clone)]
16pub struct Tag {
17 /// Tag identifier (numeric for EXIF/IPTC, string key for XMP)
18 pub id: TagId,
19 /// Canonical tag name (e.g., "ExposureTime", "Artist", "GPSLatitude")
20 pub name: String,
21 /// Human-readable description
22 pub description: String,
23 /// Group hierarchy
24 pub group: TagGroup,
25 /// The raw value
26 pub raw_value: Value,
27 /// Human-readable print conversion of the value
28 pub print_value: String,
29 /// Priority for conflict resolution (higher wins)
30 pub priority: i32,
31}
32
33impl Tag {
34 /// Get the display value respecting the print_conv option.
35 /// When `numeric` is true (-n flag), returns the raw value.
36 /// When `numeric` is false, returns the print-converted value.
37 pub fn display_value(&self, numeric: bool) -> String {
38 if numeric {
39 self.raw_value.to_display_string()
40 } else {
41 self.print_value.clone()
42 }
43 }
44}
45
46/// Tag identifier - can be numeric (EXIF/IPTC) or string (XMP).
47#[derive(Debug, Clone, PartialEq, Eq, Hash)]
48pub enum TagId {
49 /// Numeric ID (EXIF IFD tag, IPTC record:dataset)
50 Numeric(u16),
51 /// String key (XMP property path)
52 Text(String),
53}
54
55impl std::fmt::Display for TagId {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 match self {
58 TagId::Numeric(id) => write!(f, "0x{:04x}", id),
59 TagId::Text(s) => write!(f, "{}", s),
60 }
61 }
62}