Skip to main content

DragPayload

Struct DragPayload 

Source
pub struct DragPayload { /* private fields */ }
Expand description

A drag payload carrying data from a drag source to a drop target.

For intra-application transfers, use DragPayload::typed(data) to store a typed Rust value. Drop targets extract it via get_typed::<T>().

For drops from the OS, use DragPayload::external(data); targets read files() / text() / uris() (and origin() / is_external() to distinguish the source).

Implementations§

Source§

impl DragPayload

Source

pub fn typed<T: 'static>(data: T) -> Self

Create a payload from a typed Rust value.

Source

pub fn empty() -> Self

Create an empty payload (for MIME-only transfers).

Source

pub fn external(data: ExternalDropData) -> Self

Create a payload from OS-delivered external drop data.

Synthesizes canonical MIME entries (text/plain from text, text/uri-list from files + uris when not already present) so the generic get_mime API and the typed files() / text() / uris() accessors stay consistent.

Source

pub fn origin(&self) -> DragOrigin

Where this drag originated.

Source

pub fn is_external(&self) -> bool

Whether this payload came from outside the application (an OS drop).

Source

pub fn files(&self) -> &[PathBuf]

Dropped filesystem paths (empty for internal drags or non-file drops).

Source

pub fn text(&self) -> Option<&str>

Dropped plain text, if any.

Source

pub fn uris(&self) -> &[String]

Dropped non-file URLs (empty for internal drags or file-only drops).

Source

pub fn formats(&self) -> &[String]

Advertised data formats (platform MIME types / type identifiers) for an external drag. Available at drag-enter even before the bytes transfer — the basis for hover-time accept/reject when files() / text() / uris() aren’t populated yet (Wayland). See ExternalDropData::formats.

Source

pub fn with_mime(self, mime_type: &str, data: Vec<u8>) -> Self

Add a MIME-typed byte representation.

Source

pub fn enrich_external_from_mime(&mut self)

Populate the structured external view (files / text / uris) from this payload’s MIME data, so a drag that round-tripped through the OS and re-entered the app satisfies file/text drop targets (e.g. a DropZone) as well as typed in-app targets. The typed value is preserved, so get_typed::<T>() still works.

Origin is deliberately left Internal. A round-tripped drag still originated from this app, so is_external() stays false — an in-app reorder target that rejects external drags via !is_external() must still accept its own drag coming back. is_external() means “came from another application”, not “carries file/text data”. Consumers that want content should test files() / text() / uris() (or has_typed), which is what DropZone does. So a payload here can legitimately have origin == Internal and a populated external view.

No-op if an external view is already present or no recognizable MIME is carried.

Source

pub fn get_typed<T: 'static>(&self) -> Option<&T>

Extract the typed payload by type. Returns None if the type doesn’t match or no typed payload was set.

Source

pub fn take_typed<T: 'static>(&mut self) -> Option<T>

Take the typed payload, consuming it from the DragPayload.

Source

pub fn has_typed<T: 'static>(&self) -> bool

Whether this payload has a typed value of the given type.

Source

pub fn has_mime(&self, mime_type: &str) -> bool

Whether this payload has data for the given MIME type.

Source

pub fn get_mime(&self, mime_type: &str) -> Option<&[u8]>

Get MIME-typed byte data.

Source

pub fn mime_types(&self) -> Vec<&str>

List all MIME types in this payload.

Source

pub fn is_os_exportable(&self) -> bool

Whether this payload carries anything an OS drag could export. A drag becomes OS-exportable simply by populating mime_data (via Self::with_mime) or by carrying external file / text / URI data.

Source

pub fn to_outbound(&self) -> OutboundDragData

Extract the flattened, OS-exportable view used when an in-app drag escalates to an OS drag at the window boundary.

Internal drags populate only mime_data (via Self::with_mime); the files / text / uris fields come from ExternalDropData and are empty for them. So when those structured fields are absent, derive them from the canonical text/uri-list / text/plain MIME entries — the platform backends (NSURL items, etc.) need the structured form.

Trait Implementations§

Source§

impl Debug for DragPayload

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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.