pub struct ItemProvider(/* private fields */);Expand description
An NSItemProvider SwiftUI handed to a callback, or one built to hand back.
Reading what a provider carries is asynchronous — that is the whole point of the class — so what a synchronous Rust callback can see is which type identifiers it offers, which is a plain property.
Implementations§
Source§impl ItemProvider
impl ItemProvider
Sourcepub fn type_identifiers(&self) -> Vec<String>
pub fn type_identifiers(&self) -> Vec<String>
The uniform type identifiers this provider can produce.
Sourcepub fn load_plain_text(&self, then: impl FnOnce(Option<String>) + 'static)
pub fn load_plain_text(&self, then: impl FnOnce(Option<String>) + 'static)
Ask for the item’s text. The answer arrives later, on the main queue.
A drop handler could see how many items were dropped and what type identifiers they carried, and nothing about what they actually were — which is most of the way to not having a drop handler.
Asynchronous because it has to be, not as a matter of taste: measured
with a probe that waited a full second without turning the run loop, the
completion never came, and the same load with the loop running returned
immediately. NSItemProvider delivers on the main queue, so a
synchronous read from a drop handler — which is already running on the
main thread inside AppKit’s own dispatch — would wait for a block that
cannot run until it returns. Swift’s loadItem is async for the same
reason.
let drop = text("drop here").on_drop(&[ContentType::PlainText], |providers| {
for p in providers {
p.load_plain_text(|text| println!("dropped {text:?}"));
}
true
});Sourcepub fn plain_text(text: &str) -> Self
pub fn plain_text(text: &str) -> Self
Build a provider carrying text as plain text.