ferroui_base/input/i_async_data_transfer_item.rs
1use super::platform::ClipboardError;
2use super::DataFormat;
3use std::any::Any;
4use std::future::Future;
5use std::pin::Pin;
6use std::rc::Rc;
7
8/// The result of an asynchronous operation of the input system: a future
9/// that is polled on the dispatcher thread (for instance from a future
10/// started with `Dispatcher::invoke_async_task_local`).
11pub type LocalBoxFuture<T> = Pin<Box<dyn Future<Output = T>>>;
12
13/// Represent an item inside a [`IAsyncDataTransfer`](super::IAsyncDataTransfer).
14/// An item may support several formats and can return the value of a given
15/// format on demand.
16///
17/// See [`DataTransferItem`](super::DataTransferItem) for the mutable
18/// implementation.
19pub trait IAsyncDataTransferItem {
20 /// Gets the formats supported by this item.
21 fn formats(&self) -> Rc<[DataFormat]>;
22
23 /// Gets the formats supported by this item, or the failure of the
24 /// platform that provides them.
25 ///
26 /// [`formats`](Self::formats) has no way to report a failure (where the
27 /// reference throws from the property, it panics); the asynchronous
28 /// operations reading an item use this member instead, so that the
29 /// failure reaches whoever awaits them. Items whose formats cannot fail
30 /// keep the default.
31 fn try_formats(&self) -> Result<Rc<[DataFormat]>, ClipboardError> {
32 Ok(self.formats())
33 }
34
35 /// Tries to get a value for a given format. The future resolves to
36 /// `None` if the format is not supported, and to an error if the
37 /// platform providing the value fails.
38 ///
39 /// Implementations of this method are expected to return a value
40 /// matching the exact data type of the underlying
41 /// [`DataFormatOf`](super::DataFormatOf).
42 ///
43 /// To retrieve a typed value, use
44 /// [`AsyncDataTransferItemExtensions::try_get_value_async`](super::AsyncDataTransferItemExtensions::try_get_value_async).
45 fn try_get_raw_async(&self, format: &DataFormat) -> LocalBoxFuture<Result<Option<Rc<dyn Any>>, ClipboardError>>;
46}