Skip to main content

ItemProvider

Struct ItemProvider 

Source
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

Source

pub fn as_ptr(&self) -> *mut c_void

The underlying NSItemProvider.

Source

pub fn type_identifiers(&self) -> Vec<String>

The uniform type identifiers this provider can produce.

Source

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
});
Source

pub fn plain_text(text: &str) -> Self

Build a provider carrying text as plain text.

Trait Implementations§

Source§

impl Clone for ItemProvider

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for ItemProvider

Source§

impl Debug for ItemProvider

Source§

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

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

impl Send for ItemProvider

Source§

impl Sync for ItemProvider

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.