refactor(rectange tracker): relax Copy to Clone
This commit is contained in:
parent
20dfd7c236
commit
6cdb4c62ce
2 changed files with 17 additions and 15 deletions
|
|
@ -22,15 +22,15 @@ pub fn rectangle_tracking_container<'a, Message, I, T>(
|
||||||
tx: UnboundedSender<(I, Rectangle)>,
|
tx: UnboundedSender<(I, Rectangle)>,
|
||||||
) -> RectangleTrackingContainer<'a, Message, crate::Renderer, I>
|
) -> RectangleTrackingContainer<'a, Message, crate::Renderer, I>
|
||||||
where
|
where
|
||||||
I: Hash + Copy + Send + Sync + Debug + 'a,
|
I: Hash + Clone + Send + Sync + Debug + 'a,
|
||||||
T: Into<Element<'a, Message, crate::Theme, crate::Renderer>>,
|
T: Into<Element<'a, Message, crate::Theme, crate::Renderer>>,
|
||||||
{
|
{
|
||||||
RectangleTrackingContainer::new(content, id, tx)
|
RectangleTrackingContainer::new(content, id, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subscription<
|
pub fn subscription<
|
||||||
I: 'static + Hash + Copy + Send + Sync + Debug,
|
I: 'static + Hash + Clone + Send + Sync + Debug,
|
||||||
R: 'static + Hash + Copy + Send + Sync + Debug + Eq,
|
R: 'static + Hash + Clone + Send + Sync + Debug + Eq,
|
||||||
>(
|
>(
|
||||||
id: I,
|
id: I,
|
||||||
) -> iced::Subscription<(I, RectangleUpdate<R>)> {
|
) -> iced::Subscription<(I, RectangleUpdate<R>)> {
|
||||||
|
|
@ -76,7 +76,7 @@ where
|
||||||
impl<'a, Message, Renderer, I> RectangleTrackingContainer<'a, Message, Renderer, I>
|
impl<'a, Message, Renderer, I> RectangleTrackingContainer<'a, Message, Renderer, I>
|
||||||
where
|
where
|
||||||
Renderer: iced_core::Renderer,
|
Renderer: iced_core::Renderer,
|
||||||
I: 'a + Hash + Copy + Send + Sync + Debug,
|
I: 'a + Hash + Clone + Send + Sync + Debug,
|
||||||
{
|
{
|
||||||
/// Creates an empty [`Container`].
|
/// Creates an empty [`Container`].
|
||||||
pub(crate) fn new<T>(content: T, id: I, tx: UnboundedSender<(I, Rectangle)>) -> Self
|
pub(crate) fn new<T>(content: T, id: I, tx: UnboundedSender<(I, Rectangle)>) -> Self
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,16 @@ use super::RectangleTracker;
|
||||||
|
|
||||||
#[cold]
|
#[cold]
|
||||||
pub fn rectangle_tracker_subscription<
|
pub fn rectangle_tracker_subscription<
|
||||||
I: 'static + Hash + Copy + Send + Sync + Debug,
|
I: 'static + Hash + Clone + Send + Sync + Debug,
|
||||||
R: 'static + Hash + Copy + Send + Sync + Debug + Eq,
|
R: 'static + Hash + Clone + Send + Sync + Debug + Eq,
|
||||||
>(
|
>(
|
||||||
id: I,
|
id: I,
|
||||||
) -> Subscription<(I, RectangleUpdate<R>)> {
|
) -> Subscription<(I, RectangleUpdate<R>)> {
|
||||||
Subscription::run_with(id, |id| {
|
Subscription::run_with(id, |id| {
|
||||||
let id = *id;
|
let id = id.clone();
|
||||||
stream::unfold(State::Ready, move |state| start_listening(id, state))
|
stream::unfold(State::Ready, move |state| {
|
||||||
|
start_listening(id.clone(), state)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,7 +29,7 @@ pub enum State<I> {
|
||||||
Finished,
|
Finished,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start_listening<I: Copy, R: 'static + Hash + Copy + Send + Sync + Debug + Eq>(
|
async fn start_listening<I: Clone, R: 'static + Hash + Clone + Send + Sync + Debug + Eq>(
|
||||||
id: I,
|
id: I,
|
||||||
mut state: State<R>,
|
mut state: State<R>,
|
||||||
) -> Option<((I, RectangleUpdate<R>), State<R>)> {
|
) -> Option<((I, RectangleUpdate<R>), State<R>)> {
|
||||||
|
|
@ -37,7 +39,7 @@ async fn start_listening<I: Copy, R: 'static + Hash + Copy + Send + Sync + Debug
|
||||||
let (tx, rx) = unbounded();
|
let (tx, rx) = unbounded();
|
||||||
|
|
||||||
(
|
(
|
||||||
Some((id, RectangleUpdate::Init(RectangleTracker { tx }))),
|
Some((id.clone(), RectangleUpdate::Init(RectangleTracker { tx }))),
|
||||||
State::Waiting(rx, HashMap::new()),
|
State::Waiting(rx, HashMap::new()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -50,18 +52,18 @@ async fn start_listening<I: Copy, R: 'static + Hash + Copy + Send + Sync + Debug
|
||||||
|| (prev.x - new.x).abs() > 0.1
|
|| (prev.x - new.x).abs() > 0.1
|
||||||
|| (prev.y - new.y).abs() > 0.1
|
|| (prev.y - new.y).abs() > 0.1
|
||||||
{
|
{
|
||||||
map.insert(u.0, new);
|
map.insert(u.0.clone(), new);
|
||||||
(
|
(
|
||||||
Some((id, RectangleUpdate::Rectangle(u))),
|
Some((id.clone(), RectangleUpdate::Rectangle(u))),
|
||||||
State::Waiting(rx, map),
|
State::Waiting(rx, map),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(None, State::Waiting(rx, map))
|
(None, State::Waiting(rx, map))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
map.insert(u.0, u.1);
|
map.insert(u.0.clone(), u.1);
|
||||||
(
|
(
|
||||||
Some((id, RectangleUpdate::Rectangle(u))),
|
Some((id.clone(), RectangleUpdate::Rectangle(u))),
|
||||||
State::Waiting(rx, map),
|
State::Waiting(rx, map),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +82,7 @@ async fn start_listening<I: Copy, R: 'static + Hash + Copy + Send + Sync + Debug
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum RectangleUpdate<I>
|
pub enum RectangleUpdate<I>
|
||||||
where
|
where
|
||||||
I: 'static + Hash + Copy + Send + Sync + Debug,
|
I: 'static + Hash + Clone + Send + Sync + Debug,
|
||||||
{
|
{
|
||||||
Rectangle((I, Rectangle)),
|
Rectangle((I, Rectangle)),
|
||||||
Init(RectangleTracker<I>),
|
Init(RectangleTracker<I>),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue