-
-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dispatch traits aren't composable #8
Comments
Hi! I feel like adding a A more transparent way of doing this is through composition:
struct BaseQueryDispatcher<'a, D> {
root_dispatcher: &'a D
}
impl QueryDispatcher for BaseQueryDispatcher {
fn distance(...) {
// ...
if let Some(c1) = shape1.as_composite_shape() {
Ok(query::details::distance_composite_shape_shape(
self.root_dispatcher, pos12, c1, shape2,
))
}
// ....
}
}
struct DefaultQueryDispatcher;
impl QueryDispatcher for DefaultQueryDispatcher {
fn distance(...) {
let dispatcher = BaseQueryDispatcher { root_dispatcher: self };
dispatcher.distance(...)
}
} And then you can write your own dispatcher that passes itself to the |
That does look better. It might take some creativity to make composing dispatchers ergonomic (so that independently implemented custom shapes can be used without the end user writing a ton of boilerplate), but I think it's tractable; I'll play with it. |
Consider two libraries that define custom compound shapes, and an application that wants to use both. Ideally the application, which does not itself define any custom shapes, should not have to implement |
If external crates are to composably define shapes that need to dispatch recursively (i.e. compound shapes similar to HeightField), then I don't see any alternatives to the original proposal. However, end-user ergonomics could be preserved by relegating the |
When processing queries on a compound shape,
QueryDispatcher
methods must be invoked recursively. This makes it infeasible for custom shapes that occur inside compound shapes to be handled. Ideally downstream code could providechain
ableQueryDispatcher
impls that only handle the shapes they introduce and otherwise returnUnsupported
, but in that case a compound shape would fall through to the default dispatcher, which would recurse internally and fail to handle custom shapes it encounters. Similar issues affect any user-defined composite shapes. This could be fixed by adding aroot_dispatcher: &dyn QueryDispatcher
argument to every trait method. The same issue also affectsPersistentQueryDispatcher
.I can bang this out, but it's a bunch of boilerplate updates and given that this logic was not preserved from ncollide I want to be sure it's welcome before proceeding.
The text was updated successfully, but these errors were encountered: