From 17f30d1312893c7743e81c2d9a4e1022211da669 Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Sat, 3 May 2025 00:08:17 -0700 Subject: [PATCH] Compare elements by serial number, not address Rust pointers don't seem to be designed for use as identifiers, so it's probably more idiomatic and possibly more reliable to manage our own unique identifier system. https://stackoverflow.com/a/72149089 This also lets us get rid of the `ElementRc` newtype. --- app-proto/src/assembly.rs | 14 +++----------- app-proto/src/outline.rs | 6 ++---- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/app-proto/src/assembly.rs b/app-proto/src/assembly.rs index 343cef8..7841922 100644 --- a/app-proto/src/assembly.rs +++ b/app-proto/src/assembly.rs @@ -97,17 +97,9 @@ pub trait Element: ProblemPoser + DisplayItem { fn set_column_index(&self, index: usize); } -// the `Element` trait needs to be dyn-compatible, so its method signatures can -// only use `Self` in the type of the receiver. that means `Element` can't -// implement `PartialEq`. if you need partial equivalence for `Element` trait -// objects, use this wrapper -#[derive(Clone)] -pub struct ElementRc(pub Rc); - -impl PartialEq for ElementRc { - fn eq(&self, ElementRc(other): &Self) -> bool { - let ElementRc(rc) = self; - Rc::ptr_eq(rc, &other) +impl PartialEq for dyn Element { + fn eq(&self, other: &Self) -> bool { + self.serial() == other.serial() } } diff --git a/app-proto/src/outline.rs b/app-proto/src/outline.rs index 97d6ac2..7e7048d 100644 --- a/app-proto/src/outline.rs +++ b/app-proto/src/outline.rs @@ -12,7 +12,6 @@ use crate::{ assembly::{ Element, ElementKey, - ElementRc, HalfCurvatureRegulator, InversiveDistanceRegulator, Regulator, @@ -254,7 +253,6 @@ pub fn Outline() -> View { .clone() .into_iter() .sorted_by_key(|(_, elt)| elt.id().clone()) - .map(|(key, elt)| (key, ElementRc(elt))) .collect() ); @@ -268,10 +266,10 @@ pub fn Outline() -> View { ) { Keyed( list=element_list, - view=|(key, ElementRc(elt))| view! { + view=|(key, elt)| view! { ElementOutlineItem(key=key, element=elt) }, - key=|(_, ElementRc(elt))| elt.serial() + key=|(_, elt)| elt.serial() ) } }