Skip to main content

XmpMeta

Struct XmpMeta 

Source
pub struct XmpMeta { /* private fields */ }
Expand description

Main structure for working with XMP metadata

Implementations§

Source§

impl XmpMeta

Source

pub fn new() -> Self

Create a new empty XMP metadata object

Source

pub fn all_properties(&self) -> Vec<XmpProperty>

Returns all top-level properties in this metadata object.

This method returns an owned iterator (it snapshots the current state), so it can be used safely without holding internal borrows/locks across iteration.

Source

pub fn parse(s: &str) -> XmpResult<Self>

Parse XMP metadata from a string

The string should contain a complete XMP Packet (with or without the <?xpacket> wrapper).

Source

pub fn has_property(&self, namespace: &str, path: &str) -> bool

Check if a property exists

§Arguments
  • namespace - The namespace URI or prefix
  • path - The property path
Source

pub fn get_property(&self, namespace: &str, path: &str) -> Option<XmpValue>

Get a property value

§Arguments
  • namespace - The namespace URI or prefix
  • path - The property path (e.g., “CreatorTool” or “creator[1]”)
Source

pub fn set_property( &mut self, namespace: &str, path: &str, value: XmpValue, ) -> XmpResult<()>

Set a property value

§Arguments
  • namespace - The namespace URI or prefix
  • path - The property path
  • value - The value to set
Source

pub fn delete_property(&mut self, namespace: &str, path: &str) -> XmpResult<()>

Delete a property

§Arguments
  • namespace - The namespace URI or prefix
  • path - The property path
Source

pub fn about_uri(&self) -> Option<&str>

Get the about URI

Source

pub fn set_about_uri(&mut self, uri: impl Into<String>)

Set the about URI

Source

pub fn serialize(&self) -> XmpResult<String>

Serialize to RDF/XML string

Source

pub fn serialize_packet(&self) -> XmpResult<String>

Serialize to XMP Packet format

Source

pub fn serialize_packet_with_padding( &self, target_length: usize, ) -> XmpResult<String>

Serialize to XMP Packet format with padding to reach a target length

This is useful for in-place updates where the new packet needs to fit within the space of an existing packet.

§Arguments
  • target_length - The desired total packet length in bytes
§Returns
  • Ok(String) - The serialized packet with padding
  • Err(XmpError) - If the serialized packet exceeds target_length
Source

pub fn get_array_item( &self, namespace: &str, path: &str, index: usize, ) -> Option<XmpValue>

Get an array item by index

§Arguments
  • namespace - The namespace URI or prefix
  • path - The array property path (e.g., “creator”)
  • index - The array index (0-based)
Source

pub fn get_array_size(&self, namespace: &str, path: &str) -> Option<usize>

Get the size of an array property

§Arguments
  • namespace - The namespace URI or prefix
  • path - The array property path
Source

pub fn append_array_item( &mut self, namespace: &str, path: &str, value: XmpValue, ) -> XmpResult<()>

Append an item to an array property

§Arguments
  • namespace - The namespace URI or prefix
  • path - The array property path
  • value - The value to append
Source

pub fn insert_array_item( &mut self, namespace: &str, path: &str, index: usize, value: XmpValue, ) -> XmpResult<()>

Insert an item into an array property at a specific index

§Arguments
  • namespace - The namespace URI or prefix
  • path - The array property path
  • index - The index to insert at (0-based)
  • value - The value to insert
Source

pub fn delete_array_item( &mut self, namespace: &str, path: &str, index: usize, ) -> XmpResult<()>

Delete an item from an array property

§Arguments
  • namespace - The namespace URI or prefix
  • path - The array property path
  • index - The index to delete (0-based)
Source

pub fn get_struct_field( &self, namespace: &str, struct_path: &str, field_name: &str, ) -> Option<XmpValue>

Get a structure field value

§Arguments
  • namespace - The namespace URI or prefix
  • struct_path - The structure property path
  • field_name - The field name within the structure
Source

pub fn set_struct_field( &mut self, namespace: &str, struct_path: &str, field_name: &str, value: XmpValue, ) -> XmpResult<()>

Set a structure field value

§Arguments
  • namespace - The namespace URI or prefix
  • struct_path - The structure property path
  • field_name - The field name within the structure
  • value - The value to set
Source

pub fn delete_struct_field( &mut self, namespace: &str, struct_path: &str, field_name: &str, ) -> XmpResult<()>

Delete a structure field

§Arguments
  • namespace - The namespace URI or prefix
  • struct_path - The structure property path
  • field_name - The field name to delete
Source

pub fn set_localized_text( &mut self, namespace: &str, property: &str, _generic_lang: &str, specific_lang: &str, value: &str, ) -> XmpResult<()>

Set a localized text property

Localized text properties are stored as rdf:Alt arrays, where each item has an xml:lang qualifier indicating its language.

§Arguments
  • namespace - The namespace URI or prefix
  • property - The property name
  • generic_lang - Generic language code (e.g., “en”), can be empty string
  • specific_lang - Specific language code (e.g., “en-US”), required
  • value - The text value to set
§Example
use xmpkit::{XmpMeta, XmpValue};

let mut meta = XmpMeta::new();
meta.set_localized_text(
    "http://purl.org/dc/elements/1.1/",
    "title",
    "",
    "x-default",
    "Default Title"
).unwrap();
Source

pub fn get_localized_text( &self, namespace: &str, property: &str, generic_lang: &str, specific_lang: &str, ) -> Option<(String, String)>

Get a localized text property

This method searches for a localized text value matching the specified language codes. It follows XMP language matching rules:

  1. Exact match for specific_lang
  2. Match for generic_lang if specific_lang not found
  3. Fallback to “x-default” if neither found
§Arguments
  • namespace - The namespace URI or prefix
  • property - The property name
  • generic_lang - Generic language code (e.g., “en”), can be empty string
  • specific_lang - Specific language code (e.g., “en-US”), required
§Returns

Returns Some((value, actual_lang)) if found, where:

  • value is the text value
  • actual_lang is the actual language code used (may differ from requested)

Returns None if the property doesn’t exist or no matching language found.

§Example
use xmpkit::XmpMeta;

let mut meta = XmpMeta::new();
meta.set_localized_text(
    "http://purl.org/dc/elements/1.1/",
    "title",
    "",
    "x-default",
    "Default Title"
).unwrap();

let (value, lang) = meta.get_localized_text(
    "http://purl.org/dc/elements/1.1/",
    "title",
    "",
    "x-default"
).unwrap();
assert_eq!(value, "Default Title");
assert_eq!(lang, "x-default");
Source

pub fn set_date_time( &mut self, namespace: &str, path: &str, dt: &XmpDateTime, ) -> XmpResult<()>

Set a date/time property

This is a convenience method that validates and formats the date/time value before setting it as a property.

§Arguments
  • namespace - The namespace URI or prefix
  • path - The property path
  • dt - The date/time value
§Example
use xmpkit::{XmpMeta, utils::datetime::XmpDateTime};

let mut meta = XmpMeta::new();
let mut dt = XmpDateTime::new();
dt.has_date = true;
dt.has_time = true;
dt.year = 2023;
dt.month = 12;
dt.day = 25;
dt.hour = 10;
dt.minute = 30;
dt.second = 0;
dt.has_timezone = true;
dt.tz_sign = 0; // UTC

meta.set_date_time("http://ns.adobe.com/xap/1.0/", "ModifyDate", &dt).unwrap();
Source

pub fn get_date_time(&self, namespace: &str, path: &str) -> Option<XmpDateTime>

Get a date/time property

This is a convenience method that parses a date/time property value and returns it as an XmpDateTime.

§Arguments
  • namespace - The namespace URI or prefix
  • path - The property path
§Returns

Returns Some(XmpDateTime) if the property exists and can be parsed, None otherwise.

§Example
use xmpkit::{XmpMeta, XmpValue, utils::datetime::XmpDateTime};

let mut meta = XmpMeta::new();
meta.set_property(
    "http://ns.adobe.com/xap/1.0/",
    "ModifyDate",
    XmpValue::DateTime("2023-12-25T10:30:00Z".to_string())
).unwrap();

let dt = meta.get_date_time("http://ns.adobe.com/xap/1.0/", "ModifyDate").unwrap();
assert_eq!(dt.year, 2023);
assert_eq!(dt.month, 12);
assert_eq!(dt.day, 25);

Trait Implementations§

Source§

impl Clone for XmpMeta

Source§

fn clone(&self) -> XmpMeta

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for XmpMeta

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for XmpMeta

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl FromStr for XmpMeta

Source§

type Err = XmpError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V