Skip to content

Commit 216f794

Browse files
committed
Clean up implementation, and prep for draft PR
1 parent 0d9a5ec commit 216f794

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

core/lib/src/router/unique_property.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ impl Sealed for Host<'static> {}
7676
impl UniqueProperty for MediaType {
7777
fn collides(&self, self_route: &Route, other_route: &Route) -> Option<bool> {
7878
match (self_route.method.allows_request_body(), other_route.method.allows_request_body()) {
79-
(Some(true), Some(true)) => other_route.get_unique_prop().map(|other| self.collides_with(other)),
80-
_ => Some(true),
79+
(Some(true), Some(true)) => other_route
80+
.get_unique_prop()
81+
.map(|other| self.collides_with(other)),
82+
_ => None, // Does not differentiate routes
8183
}
8284
}
8385

@@ -101,25 +103,15 @@ pub(crate) fn dyn_box_any(b: &Box<dyn UniqueProperty>) -> &dyn Any {
101103
let any = b.as_any();
102104
assert_eq!(b.type_id(), any.type_id());
103105
any
104-
// <Box<dyn UniqueProperty> as AsRef<dyn UniqueProperty>>::as_ref(b).as_any()
105-
// todo!()
106106
}
107107

108108
/// A set of properties is unambiguous iff there is at least one property shared by both sets, with
109109
/// a different value.
110110
pub(crate) fn collides(a: &Route, b: &Route) -> bool {
111111
for prop_a in &a.unique_properties {
112-
for prop_b in &b.unique_properties {
113-
// Check that they have the same type_id, which prevents checking other properties (and potentially
114-
// avoids the need to check the reverse)
115-
dbg!((prop_a.type_id(), prop_b.type_id(), prop_a.type_id() == prop_b.type_id()));
116-
dbg!(prop_a.collides(a, b));
117-
// `prop_b.as_ref()` is needed to ensure we do not convert `Box<dyn _>` into `&dyn Any`, but rather
118-
// get the inner type
119-
// assert_eq!(std::any::TypeId::of::<MediaType>(), dyn_box_any(prop_b).type_id());
120-
if dyn_box_any(prop_a).type_id() == dyn_box_any(prop_b).type_id() && prop_a.collides(a, b) == Some(false) {
121-
return false;
122-
}
112+
// TODO: we should consider checking the inverse, i.e., does b collide with a
113+
if prop_a.collides(a, b) == Some(false) {
114+
return false;
123115
}
124116
}
125117
true

0 commit comments

Comments
 (0)