Use pointers to refer to elements and regulators #84
2 changed files with 5 additions and 15 deletions
|
@ -97,17 +97,9 @@ pub trait Element: ProblemPoser + DisplayItem {
|
||||||
fn set_column_index(&self, index: usize);
|
fn set_column_index(&self, index: usize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// the `Element` trait needs to be dyn-compatible, so its method signatures can
|
impl PartialEq for dyn Element {
|
||||||
// only use `Self` in the type of the receiver. that means `Element` can't
|
fn eq(&self, other: &Self) -> bool {
|
||||||
// implement `PartialEq`. if you need partial equivalence for `Element` trait
|
self.serial() == other.serial()
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ use crate::{
|
||||||
assembly::{
|
assembly::{
|
||||||
Element,
|
Element,
|
||||||
ElementKey,
|
ElementKey,
|
||||||
ElementRc,
|
|
||||||
HalfCurvatureRegulator,
|
HalfCurvatureRegulator,
|
||||||
InversiveDistanceRegulator,
|
InversiveDistanceRegulator,
|
||||||
Regulator,
|
Regulator,
|
||||||
|
@ -254,7 +253,6 @@ pub fn Outline() -> View {
|
||||||
.clone()
|
.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.sorted_by_key(|(_, elt)| elt.id().clone())
|
.sorted_by_key(|(_, elt)| elt.id().clone())
|
||||||
.map(|(key, elt)| (key, ElementRc(elt)))
|
|
||||||
.collect()
|
.collect()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -268,10 +266,10 @@ pub fn Outline() -> View {
|
||||||
) {
|
) {
|
||||||
Keyed(
|
Keyed(
|
||||||
list=element_list,
|
list=element_list,
|
||||||
view=|(key, ElementRc(elt))| view! {
|
view=|(key, elt)| view! {
|
||||||
ElementOutlineItem(key=key, element=elt)
|
ElementOutlineItem(key=key, element=elt)
|
||||||
},
|
},
|
||||||
key=|(_, ElementRc(elt))| elt.serial()
|
key=|(_, elt)| elt.serial()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue