From 9af24fd6a983aead39f890d087bed89bef35cbcb Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 30 Oct 2022 18:57:50 -0700 Subject: [PATCH] Allow `XmpMeta::array_item` to accept `XmpMeta::LAST_ITEM` (#127) --- src/ffi.rs | 2 +- src/tests/xmp_meta.rs | 13 +++++++++++++ src/xmp_meta.rs | 10 +++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/ffi.rs b/src/ffi.rs index 595c097..359d92d 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -392,7 +392,7 @@ extern "C" { out_error: *mut CXmpError, schema_ns: *const c_char, prop_name: *const c_char, - index: u32, + index: i32, out_options: *mut u32, ) -> *const c_char; diff --git a/src/tests/xmp_meta.rs b/src/tests/xmp_meta.rs index a67c058..57ad827 100644 --- a/src/tests/xmp_meta.rs +++ b/src/tests/xmp_meta.rs @@ -1664,6 +1664,19 @@ mod array_item { ); } + #[test] + fn last_item() { + let m = XmpMeta::from_str(ARRAY_EXAMPLE).unwrap(); + + assert_eq!( + m.array_item(xmp_ns::DC, "subject", XmpMeta::LAST_ITEM), + Some(XmpValue { + value: "test".to_owned(), + options: 0 + }) + ); + } + #[test] fn item_options() { let mut m = XmpMeta::from_str(ARRAY_EXAMPLE).unwrap(); diff --git a/src/xmp_meta.rs b/src/xmp_meta.rs index 0374a1c..3be5e64 100644 --- a/src/xmp_meta.rs +++ b/src/xmp_meta.rs @@ -820,14 +820,14 @@ impl XmpMeta { /// /// * `namespace` and `array_name`: See [Accessing /// properties](#accessing-properties). - /// * `item_index`: Index into the array. - /// **IMPORTANT:** Indices in XMP are 1-based, unlike Rust where - /// indices are typically 0-based. + /// * `item_index`: Index into the array. **IMPORTANT:** Indices in XMP are + /// 1-based, unlike Rust where indices are typically 0-based. Use + /// [`XmpMeta::LAST_ITEM`] to specify the last existing array item. pub fn array_item( &self, namespace: &str, array_name: &str, - item_index: u32, + item_index: i32, ) -> Option> { if let Some(m) = self.m { let c_ns = CString::new(namespace).unwrap_or_default(); @@ -1506,7 +1506,7 @@ pub struct ArrayProperty<'a> { meta: &'a XmpMeta, ns: CString, name: CString, - index: u32, + index: i32, } impl<'a> Iterator for ArrayProperty<'a> {