Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Send for XmpMeta #158

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/tests/xmp_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3405,3 +3405,41 @@ mod impl_display {
);
}
}

mod impl_send {
use std::str::FromStr;

use crate::{tests::fixtures::*, XmpMeta, XmpValue};

#[test]
fn happy_path() {
use std::thread;

let other_thread = thread::spawn(|| XmpMeta::from_str(PURPLE_SQUARE_XMP));

let result = other_thread.join().unwrap();
let m = result.unwrap();

assert_eq!(
m.property("http://ns.adobe.com/xap/1.0/", "CreatorTool")
.unwrap(),
XmpValue {
value: "Adobe Photoshop CS2 Windows".to_owned(),
options: 0
}
);

assert_eq!(
m.property("http://ns.adobe.com/photoshop/1.0/", "ICCProfile")
.unwrap(),
XmpValue {
value: "Dell 1905FP Color Profile".to_owned(),
options: 0
}
);

assert!(m
.property("http://ns.adobe.com/photoshop/1.0/", "ICCProfilx")
.is_none());
}
}
11 changes: 11 additions & 0 deletions src/xmp_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,17 @@ impl FromStr for XmpMeta {
}
}

/// Per _XMP Toolkit SDK Programmer's Guide_, section _Multi-threading in the
/// API:_
///
/// > The functions in XMPCore and XMPFiles are thread safe. You must call the
/// > initialization and termination
/// > functions in a single-threaded manner; between those calls, you can use
/// > threads freely, following a
/// > multi-read, single-writer locking model. All locking is automatic and
/// > transparent.
unsafe impl Send for XmpMeta {}

/// An iterator that provides access to items within a property array.
///
/// Create via [`XmpMeta::property_array`].
Expand Down