summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--native/src/clipboard.rs7
-rw-r--r--native/src/command.rs8
-rw-r--r--native/src/command/action.rs7
-rw-r--r--native/src/debug/basic.rs4
-rw-r--r--native/src/lib.rs1
-rw-r--r--native/src/mouse/click.rs11
-rw-r--r--native/src/subscription.rs20
7 files changed, 38 insertions, 20 deletions
diff --git a/native/src/clipboard.rs b/native/src/clipboard.rs
index 60703c31..c9105bc0 100644
--- a/native/src/clipboard.rs
+++ b/native/src/clipboard.rs
@@ -1,4 +1,6 @@
//! Access the clipboard.
+use iced_futures::MaybeSend;
+
use std::fmt;
/// A buffer for short-term storage and transfer within and between
@@ -36,7 +38,10 @@ pub enum Action<T> {
impl<T> Action<T> {
/// Maps the output of a clipboard [`Action`] using the provided closure.
- pub fn map<A>(self, f: impl Fn(T) -> A + 'static + Send + Sync) -> Action<A>
+ pub fn map<A>(
+ self,
+ f: impl Fn(T) -> A + 'static + MaybeSend + Sync,
+ ) -> Action<A>
where
T: 'static,
{
diff --git a/native/src/command.rs b/native/src/command.rs
index 6fe518d7..89d0f045 100644
--- a/native/src/command.rs
+++ b/native/src/command.rs
@@ -3,6 +3,8 @@ mod action;
pub use action::Action;
+use iced_futures::MaybeSend;
+
use std::fmt;
use std::future::Future;
@@ -24,8 +26,8 @@ impl<T> Command<T> {
/// Creates a [`Command`] that performs the action of the given future.
pub fn perform<A>(
- future: impl Future<Output = T> + 'static + Send,
- f: impl Fn(T) -> A + 'static + Send,
+ future: impl Future<Output = T> + 'static + MaybeSend,
+ f: impl Fn(T) -> A + 'static + MaybeSend,
) -> Command<A> {
use iced_futures::futures::FutureExt;
@@ -45,7 +47,7 @@ impl<T> Command<T> {
/// Applies a transformation to the result of a [`Command`].
pub fn map<A>(
self,
- f: impl Fn(T) -> A + 'static + Send + Sync + Clone,
+ f: impl Fn(T) -> A + 'static + MaybeSend + Sync + Clone,
) -> Command<A>
where
T: 'static,
diff --git a/native/src/command/action.rs b/native/src/command/action.rs
index 77be1b59..5c7509c8 100644
--- a/native/src/command/action.rs
+++ b/native/src/command/action.rs
@@ -1,6 +1,8 @@
use crate::clipboard;
use crate::window;
+use iced_futures::MaybeSend;
+
use std::fmt;
/// An action that a [`Command`] can perform.
@@ -19,7 +21,10 @@ pub enum Action<T> {
impl<T> Action<T> {
/// Applies a transformation to the result of a [`Command`].
- pub fn map<A>(self, f: impl Fn(T) -> A + 'static + Send + Sync) -> Action<A>
+ pub fn map<A>(
+ self,
+ f: impl Fn(T) -> A + 'static + MaybeSend + Sync,
+ ) -> Action<A>
where
T: 'static,
{
diff --git a/native/src/debug/basic.rs b/native/src/debug/basic.rs
index a42f66ea..d706bb00 100644
--- a/native/src/debug/basic.rs
+++ b/native/src/debug/basic.rs
@@ -1,5 +1,7 @@
#![allow(missing_docs)]
-use std::{collections::VecDeque, time};
+use crate::time;
+
+use std::collections::VecDeque;
/// A bunch of time measurements for debugging purposes.
#[derive(Debug)]
diff --git a/native/src/lib.rs b/native/src/lib.rs
index a5526e6d..6d98f7d1 100644
--- a/native/src/lib.rs
+++ b/native/src/lib.rs
@@ -69,6 +69,7 @@ mod debug;
mod debug;
pub use iced_core::alignment;
+pub use iced_core::time;
pub use iced_core::{
Alignment, Background, Color, Font, Length, Padding, Point, Rectangle,
Size, Vector,
diff --git a/native/src/mouse/click.rs b/native/src/mouse/click.rs
index 6c8b61a5..4a7d796c 100644
--- a/native/src/mouse/click.rs
+++ b/native/src/mouse/click.rs
@@ -1,6 +1,6 @@
//! Track mouse clicks.
+use crate::time::Instant;
use crate::Point;
-use std::time::Instant;
/// A mouse click.
#[derive(Debug, Clone, Copy)]
@@ -62,9 +62,14 @@ impl Click {
}
fn is_consecutive(&self, new_position: Point, time: Instant) -> bool {
+ let duration = if time > self.time {
+ Some(time - self.time)
+ } else {
+ None
+ };
+
self.position == new_position
- && time
- .checked_duration_since(self.time)
+ && duration
.map(|duration| duration.as_millis() <= 300)
.unwrap_or(false)
}
diff --git a/native/src/subscription.rs b/native/src/subscription.rs
index 63834654..9775c84b 100644
--- a/native/src/subscription.rs
+++ b/native/src/subscription.rs
@@ -3,7 +3,7 @@ use crate::event::{self, Event};
use crate::Hasher;
use iced_futures::futures::{self, Future, Stream};
-use iced_futures::BoxStream;
+use iced_futures::{BoxStream, MaybeSend};
use std::hash::Hash;
@@ -56,7 +56,7 @@ pub fn events_with<Message>(
f: fn(Event, event::Status) -> Option<Message>,
) -> Subscription<Message>
where
- Message: 'static + Send,
+ Message: 'static + MaybeSend,
{
Subscription::from_recipe(Runner {
id: f,
@@ -78,7 +78,7 @@ where
pub fn run<I, S, Message>(id: I, stream: S) -> Subscription<Message>
where
I: Hash + 'static,
- S: Stream<Item = Message> + Send + 'static,
+ S: Stream<Item = Message> + MaybeSend + 'static,
Message: 'static,
{
Subscription::from_recipe(Runner {
@@ -159,13 +159,13 @@ where
pub fn unfold<I, T, Fut, Message>(
id: I,
initial: T,
- mut f: impl FnMut(T) -> Fut + Send + Sync + 'static,
+ mut f: impl FnMut(T) -> Fut + MaybeSend + Sync + 'static,
) -> Subscription<Message>
where
I: Hash + 'static,
- T: Send + 'static,
- Fut: Future<Output = (Option<Message>, T)> + Send + 'static,
- Message: 'static + Send,
+ T: MaybeSend + 'static,
+ Fut: Future<Output = (Option<Message>, T)> + MaybeSend + 'static,
+ Message: 'static + MaybeSend,
{
use futures::future::{self, FutureExt};
use futures::stream::StreamExt;
@@ -191,7 +191,7 @@ impl<I, S, F, Message> Recipe<Hasher, (Event, event::Status)>
where
I: Hash + 'static,
F: FnOnce(EventStream) -> S,
- S: Stream<Item = Message> + Send + 'static,
+ S: Stream<Item = Message> + MaybeSend + 'static,
{
type Output = Message;
@@ -201,8 +201,6 @@ where
}
fn stream(self: Box<Self>, input: EventStream) -> BoxStream<Self::Output> {
- use futures::stream::StreamExt;
-
- (self.spawn)(input).boxed()
+ iced_futures::boxed_stream((self.spawn)(input))
}
}