pub struct DragPayload {
pub drag_type: String,
pub data: Vec<u8>,
pub display_text: Option<String>,
}Expand description
Data carried during a drag operation.
The payload uses a MIME-like type string for matching against drop targets and raw bytes for the actual data. This decouples the drag source from the drop target — they only need to agree on the type string and byte format.
§Examples
let payload = DragPayload::text("hello world");
assert_eq!(payload.drag_type, "text/plain");
assert_eq!(payload.display_text.as_deref(), Some("hello world"));Fields§
§drag_type: StringMIME-like type identifier (e.g., "text/plain", "widget/list-item").
data: Vec<u8>Raw serialized data.
display_text: Option<String>Human-readable preview text shown during drag (optional).
Implementations§
Source§impl DragPayload
impl DragPayload
Sourcepub fn new(drag_type: impl Into<String>, data: Vec<u8>) -> Self
pub fn new(drag_type: impl Into<String>, data: Vec<u8>) -> Self
Create a payload with raw bytes.
Sourcepub fn with_display_text(self, text: impl Into<String>) -> Self
pub fn with_display_text(self, text: impl Into<String>) -> Self
Create a payload with custom display text.
Sourcepub fn matches_type(&self, pattern: &str) -> bool
pub fn matches_type(&self, pattern: &str) -> bool
Returns true if the payload type matches the given pattern.
Supports exact match and wildcard prefix (e.g., "text/*").
Trait Implementations§
Source§impl Clone for DragPayload
impl Clone for DragPayload
Source§fn clone(&self) -> DragPayload
fn clone(&self) -> DragPayload
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for DragPayload
impl RefUnwindSafe for DragPayload
impl Send for DragPayload
impl Sync for DragPayload
impl Unpin for DragPayload
impl UnwindSafe for DragPayload
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more