pub struct XmpMeta { /* private fields */ }Expand description
Main structure for working with XMP metadata
Implementations§
Source§impl XmpMeta
impl XmpMeta
Sourcepub fn all_properties(&self) -> Vec<XmpProperty>
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.
Sourcepub fn parse(s: &str) -> XmpResult<Self>
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).
Sourcepub fn has_property(&self, namespace: &str, path: &str) -> bool
pub fn has_property(&self, namespace: &str, path: &str) -> bool
Check if a property exists
§Arguments
namespace- The namespace URI or prefixpath- The property path
Sourcepub fn get_property(&self, namespace: &str, path: &str) -> Option<XmpValue>
pub fn get_property(&self, namespace: &str, path: &str) -> Option<XmpValue>
Get a property value
§Arguments
namespace- The namespace URI or prefixpath- The property path (e.g., “CreatorTool” or “creator[1]”)
Sourcepub fn set_property(
&mut self,
namespace: &str,
path: &str,
value: XmpValue,
) -> XmpResult<()>
pub fn set_property( &mut self, namespace: &str, path: &str, value: XmpValue, ) -> XmpResult<()>
Set a property value
§Arguments
namespace- The namespace URI or prefixpath- The property pathvalue- The value to set
Sourcepub fn set_about_uri(&mut self, uri: impl Into<String>)
pub fn set_about_uri(&mut self, uri: impl Into<String>)
Set the about URI
Sourcepub fn serialize_packet(&self) -> XmpResult<String>
pub fn serialize_packet(&self) -> XmpResult<String>
Serialize to XMP Packet format
Sourcepub fn serialize_packet_with_padding(
&self,
target_length: usize,
) -> XmpResult<String>
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 paddingErr(XmpError)- If the serialized packet exceeds target_length
Sourcepub fn get_array_item(
&self,
namespace: &str,
path: &str,
index: usize,
) -> Option<XmpValue>
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 prefixpath- The array property path (e.g., “creator”)index- The array index (0-based)
Sourcepub fn get_array_size(&self, namespace: &str, path: &str) -> Option<usize>
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 prefixpath- The array property path
Sourcepub fn append_array_item(
&mut self,
namespace: &str,
path: &str,
value: XmpValue,
) -> XmpResult<()>
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 prefixpath- The array property pathvalue- The value to append
Sourcepub fn insert_array_item(
&mut self,
namespace: &str,
path: &str,
index: usize,
value: XmpValue,
) -> XmpResult<()>
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 prefixpath- The array property pathindex- The index to insert at (0-based)value- The value to insert
Sourcepub fn delete_array_item(
&mut self,
namespace: &str,
path: &str,
index: usize,
) -> XmpResult<()>
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 prefixpath- The array property pathindex- The index to delete (0-based)
Sourcepub fn get_struct_field(
&self,
namespace: &str,
struct_path: &str,
field_name: &str,
) -> Option<XmpValue>
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 prefixstruct_path- The structure property pathfield_name- The field name within the structure
Sourcepub fn set_struct_field(
&mut self,
namespace: &str,
struct_path: &str,
field_name: &str,
value: XmpValue,
) -> XmpResult<()>
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 prefixstruct_path- The structure property pathfield_name- The field name within the structurevalue- The value to set
Sourcepub fn delete_struct_field(
&mut self,
namespace: &str,
struct_path: &str,
field_name: &str,
) -> XmpResult<()>
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 prefixstruct_path- The structure property pathfield_name- The field name to delete
Sourcepub fn set_localized_text(
&mut self,
namespace: &str,
property: &str,
_generic_lang: &str,
specific_lang: &str,
value: &str,
) -> XmpResult<()>
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 prefixproperty- The property namegeneric_lang- Generic language code (e.g., “en”), can be empty stringspecific_lang- Specific language code (e.g., “en-US”), requiredvalue- 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();Sourcepub fn get_localized_text(
&self,
namespace: &str,
property: &str,
generic_lang: &str,
specific_lang: &str,
) -> Option<(String, String)>
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:
- Exact match for specific_lang
- Match for generic_lang if specific_lang not found
- Fallback to “x-default” if neither found
§Arguments
namespace- The namespace URI or prefixproperty- The property namegeneric_lang- Generic language code (e.g., “en”), can be empty stringspecific_lang- Specific language code (e.g., “en-US”), required
§Returns
Returns Some((value, actual_lang)) if found, where:
valueis the text valueactual_langis 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");Sourcepub fn set_date_time(
&mut self,
namespace: &str,
path: &str,
dt: &XmpDateTime,
) -> XmpResult<()>
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 prefixpath- The property pathdt- 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();Sourcepub fn get_date_time(&self, namespace: &str, path: &str) -> Option<XmpDateTime>
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 prefixpath- 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§
Auto Trait Implementations§
impl Freeze for XmpMeta
impl RefUnwindSafe for XmpMeta
impl Send for XmpMeta
impl Sync for XmpMeta
impl Unpin for XmpMeta
impl UnsafeUnpin for XmpMeta
impl UnwindSafe for XmpMeta
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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