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)>,
|
||||
) -> RectangleTrackingContainer<'a, Message, crate::Renderer, I>
|
||||
where
|
||||
I: Hash + Copy + Send + Sync + Debug + 'a,
|
||||
I: Hash + Clone + Send + Sync + Debug + 'a,
|
||||
T: Into<Element<'a, Message, crate::Theme, crate::Renderer>>,
|
||||
{
|
||||
RectangleTrackingContainer::new(content, id, tx)
|
||||
}
|
||||
|
||||
pub fn subscription<
|
||||
I: 'static + Hash + Copy + Send + Sync + Debug,
|
||||
R: 'static + Hash + Copy + Send + Sync + Debug + Eq,
|
||||
I: 'static + Hash + Clone + Send + Sync + Debug,
|
||||
R: 'static + Hash + Clone + Send + Sync + Debug + Eq,
|
||||
>(
|
||||
id: I,
|
||||
) -> iced::Subscription<(I, RectangleUpdate<R>)> {
|
||||
|
|
@ -76,7 +76,7 @@ where
|
|||
impl<'a, Message, Renderer, I> RectangleTrackingContainer<'a, Message, Renderer, I>
|
||||
where
|
||||
Renderer: iced_core::Renderer,
|
||||
I: 'a + Hash + Copy + Send + Sync + Debug,
|
||||
I: 'a + Hash + Clone + Send + Sync + Debug,
|
||||
{
|
||||
/// Creates an empty [`Container`].
|
||||
pub(crate) fn new<T>(content: T, id: I, tx: UnboundedSender<(I, Rectangle)>) -> Self
|
||||
|
|
|
|||
|
|
@ -10,14 +10,16 @@ use super::RectangleTracker;
|
|||
|
||||
#[cold]
|
||||
pub fn rectangle_tracker_subscription<
|
||||
I: 'static + Hash + Copy + Send + Sync + Debug,
|
||||
R: 'static + Hash + Copy + Send + Sync + Debug + Eq,
|
||||
I: 'static + Hash + Clone + Send + Sync + Debug,
|
||||
R: 'static + Hash + Clone + Send + Sync + Debug + Eq,
|
||||
>(
|
||||
id: I,
|
||||
) -> Subscription<(I, RectangleUpdate<R>)> {
|
||||
Subscription::run_with(id, |id| {
|
||||
let id = *id;
|
||||
stream::unfold(State::Ready, move |state| start_listening(id, state))
|
||||
let id = id.clone();
|
||||
stream::unfold(State::Ready, move |state| {
|
||||
start_listening(id.clone(), state)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -27,7 +29,7 @@ pub enum State<I> {
|
|||
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,
|
||||
mut state: 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();
|
||||
|
||||
(
|
||||
Some((id, RectangleUpdate::Init(RectangleTracker { tx }))),
|
||||
Some((id.clone(), RectangleUpdate::Init(RectangleTracker { tx }))),
|
||||
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.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),
|
||||
)
|
||||
} else {
|
||||
(None, State::Waiting(rx, map))
|
||||
}
|
||||
} 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),
|
||||
)
|
||||
}
|
||||
|
|
@ -80,7 +82,7 @@ async fn start_listening<I: Copy, R: 'static + Hash + Copy + Send + Sync + Debug
|
|||
#[derive(Clone, Debug)]
|
||||
pub enum RectangleUpdate<I>
|
||||
where
|
||||
I: 'static + Hash + Copy + Send + Sync + Debug,
|
||||
I: 'static + Hash + Clone + Send + Sync + Debug,
|
||||
{
|
||||
Rectangle((I, Rectangle)),
|
||||
Init(RectangleTracker<I>),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue