pub struct DataTransferSendBuilder<T> { /* private fields */ }Expand description
Dynamic builder for an implementation of DataTransferSend.
On all platforms, inter-application data transfer (i.e. clipboard and drag-and-drop) works like so:
- The source advertises a set of types that it can transfer.
- The destination picks one or more of those types to receive.
- The source sends the data for that type.
This type abstracts that in a way that allows data to be sent cross-platform. T is an optional
state value, which allows the user to have a single source of truth for their data, converting
it lazily to the requested type.
Implementations§
Source§impl<T> DataTransferSendBuilder<T>
impl<T> DataTransferSendBuilder<T>
Sourcepub fn new(state: T) -> Self
pub fn new(state: T) -> Self
Create a new DataTransferSendBuilder, with a state value which acts as
the single source of truth for the underlying data.
Source§impl<T> DataTransferSendBuilder<T>
impl<T> DataTransferSendBuilder<T>
Sourcepub fn add_type<Ty, F, O>(&mut self, type_: Ty, func: F) -> &mut Selfwhere
Ty: TransferType + Send,
F: Fn(&T, &dyn TransferType) -> Option<O> + Send + 'static,
O: Into<SendData>,
pub fn add_type<Ty, F, O>(&mut self, type_: Ty, func: F) -> &mut Selfwhere
Ty: TransferType + Send,
F: Fn(&T, &dyn TransferType) -> Option<O> + Send + 'static,
O: Into<SendData>,
Add a callback which converts the builder’s state to the given type. In
most cases, type_ will be TypeHint.
Sourcepub fn with_type<Ty, F, O>(self, type_: Ty, func: F) -> Selfwhere
Ty: TransferType + Send,
F: Fn(&T, &dyn TransferType) -> Option<O> + Send + 'static,
O: Into<SendData>,
pub fn with_type<Ty, F, O>(self, type_: Ty, func: F) -> Selfwhere
Ty: TransferType + Send,
F: Fn(&T, &dyn TransferType) -> Option<O> + Send + 'static,
O: Into<SendData>,
Return a new builder, adding a callback which converts the builder’s state to the given type.
For cross-platform use, type_ will be TypeHint. The closure additionally receives
a TransferType, which is not necessarily the same as type_ for the following reasons:
- The OS may have multiple types which are equivalent to the supplied type
TypeHint::AudioandTypeHint::Imagewithextension_hint: Nonewill advertise all supported audio and image formats, in which case the closure may receive a type with an extension chosen by the receiving application.
Source§impl<T> DataTransferSendBuilder<T>
impl<T> DataTransferSendBuilder<T>
Sourcepub fn build(self) -> Box<dyn DataTransferSend>
pub fn build(self) -> Box<dyn DataTransferSend>
Consume the builder, returning an implementation of DataTransferSend.
Note that this is only provided for explicitness and ergonomics. DataTransferSendBuilder
implements DataTransferSend and this method is equivalent to Box::new.
Trait Implementations§
Source§impl<T> DataTransfer for DataTransferSendBuilder<T>
impl<T> DataTransfer for DataTransferSendBuilder<T>
Source§fn for_each_available_type<'this>(
&'this self,
func: &mut dyn FnMut(&'this dyn TransferType) -> ControlFlow<()>,
)
fn for_each_available_type<'this>( &'this self, func: &mut dyn FnMut(&'this dyn TransferType) -> ControlFlow<()>, )
DataTransfer. This is just a minor optimization,
in most cases you should probably use has_type or
available_types.Source§fn available_types(&self) -> Vec<&dyn TransferType>
fn available_types(&self) -> Vec<&dyn TransferType>
Source§fn has_type(&self, type_: &dyn TransferType) -> bool
fn has_type(&self, type_: &dyn TransferType) -> bool
DataTransfer. Read moreSource§impl<T> DataTransferSend for DataTransferSendBuilder<T>
impl<T> DataTransferSend for DataTransferSendBuilder<T>
Source§fn data_for_type(&self, type_: &dyn TransferType) -> Option<SendData>
fn data_for_type(&self, type_: &dyn TransferType) -> Option<SendData>
None if this value does not supply the given data
type.