Use pointers to refer to elements and regulators #84

Merged
glen merged 10 commits from Vectornaut/dyna3:use-pointers into main 2025-05-06 19:17:31 +00:00
2 changed files with 5 additions and 15 deletions
Showing only changes of commit 17f30d1312 - Show all commits

View file

@ -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<dyn Element>);
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()
}
}

View file

@ -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()
)
}
}