Skip to main content

DataTransferSendBuilder

Struct DataTransferSendBuilder 

Source
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>

Source

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>

Source

pub fn add_type<Ty, F, O>(&mut self, type_: Ty, func: F) -> &mut Self
where 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.

Source

pub fn with_type<Ty, F, O>(self, type_: Ty, func: F) -> Self
where 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::Audio and TypeHint::Image with extension_hint: None will 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>
where T: Debug + Send + 'static,

Source

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>
where T: Debug + Send + 'static,

Source§

fn for_each_available_type<'this>( &'this self, func: &mut dyn FnMut(&'this dyn TransferType) -> ControlFlow<()>, )

Iterate over each type advertized by this 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>

Display the list of all available types. Read more
Source§

fn has_type(&self, type_: &dyn TransferType) -> bool

Check if the supplied type is provided by this DataTransfer. Read more
Source§

impl<T> DataTransferSend for DataTransferSendBuilder<T>
where T: Debug + Send + 'static,

Source§

fn data_for_type(&self, type_: &dyn TransferType) -> Option<SendData>

Get the data for the specified type, or None if this value does not supply the given data type.
Source§

impl<T> Debug for DataTransferSendBuilder<T>
where T: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for DataTransferSendBuilder<T>

§

impl<T> !Sync for DataTransferSendBuilder<T>

§

impl<T> !UnwindSafe for DataTransferSendBuilder<T>

§

impl<T> Freeze for DataTransferSendBuilder<T>
where T: Freeze, Vec<(Box<dyn TransferType + Send>, Box<dyn Fn(&T, &(dyn TransferType + 'static)) -> Option<SendData> + Send>)>: Freeze,

§

impl<T> Send for DataTransferSendBuilder<T>
where T: Send, Vec<(Box<dyn TransferType + Send>, Box<dyn Fn(&T, &(dyn TransferType + 'static)) -> Option<SendData> + Send>)>: Send,

§

impl<T> Unpin for DataTransferSendBuilder<T>
where T: Unpin, Vec<(Box<dyn TransferType + Send>, Box<dyn Fn(&T, &(dyn TransferType + 'static)) -> Option<SendData> + Send>)>: Unpin,

§

impl<T> UnsafeUnpin for DataTransferSendBuilder<T>
where T: UnsafeUnpin, Vec<(Box<dyn TransferType + Send>, Box<dyn Fn(&T, &(dyn TransferType + 'static)) -> Option<SendData> + Send>)>: UnsafeUnpin,

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.