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
impl DragPayload
Sourcepub fn external(data: ExternalDropData) -> Self
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.
Sourcepub fn origin(&self) -> DragOrigin
pub fn origin(&self) -> DragOrigin
Where this drag originated.
Sourcepub fn is_external(&self) -> bool
pub fn is_external(&self) -> bool
Whether this payload came from outside the application (an OS drop).
Sourcepub fn files(&self) -> &[PathBuf]
pub fn files(&self) -> &[PathBuf]
Dropped filesystem paths (empty for internal drags or non-file drops).
Sourcepub fn uris(&self) -> &[String]
pub fn uris(&self) -> &[String]
Dropped non-file URLs (empty for internal drags or file-only drops).
Sourcepub fn formats(&self) -> &[String]
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.
Sourcepub fn with_mime(self, mime_type: &str, data: Vec<u8>) -> Self
pub fn with_mime(self, mime_type: &str, data: Vec<u8>) -> Self
Add a MIME-typed byte representation.
Sourcepub fn enrich_external_from_mime(&mut self)
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.
Sourcepub fn get_typed<T: 'static>(&self) -> Option<&T>
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.
Sourcepub fn take_typed<T: 'static>(&mut self) -> Option<T>
pub fn take_typed<T: 'static>(&mut self) -> Option<T>
Take the typed payload, consuming it from the DragPayload.
Sourcepub fn has_typed<T: 'static>(&self) -> bool
pub fn has_typed<T: 'static>(&self) -> bool
Whether this payload has a typed value of the given type.
Sourcepub fn has_mime(&self, mime_type: &str) -> bool
pub fn has_mime(&self, mime_type: &str) -> bool
Whether this payload has data for the given MIME type.
Sourcepub fn mime_types(&self) -> Vec<&str>
pub fn mime_types(&self) -> Vec<&str>
List all MIME types in this payload.
Sourcepub fn is_os_exportable(&self) -> bool
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.
Sourcepub fn to_outbound(&self) -> OutboundDragData
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.