Struct QueryDispatcherChain

Source
pub struct QueryDispatcherChain<T, U>(/* private fields */);
Expand description

A chain of two query dispatchers that provides fallback behavior.

This struct is created by calling QueryDispatcher::chain() and allows combining multiple dispatchers into a fallback sequence. When a query is performed:

  1. The first dispatcher (T) is tried
  2. If it returns Err(Unsupported), the second dispatcher (U) is tried
  3. If the second also returns Unsupported, the error is propagated

§Use Cases

Dispatcher chains are useful for:

  • Custom shapes with default fallback: Handle your custom shapes specifically, but fall back to Parry’s default dispatcher for standard shapes

  • Performance optimization: Try a fast specialized algorithm first, fall back to a general but slower algorithm if needed

  • Progressive feature support: Layer dispatchers that support different feature sets

  • Debugging: Wrap the default dispatcher with a logging dispatcher that passes through

§Example

use parry3d::query::{QueryDispatcher, DefaultQueryDispatcher};

// A dispatcher that handles only custom shapes
struct CustomShapeDispatcher;
impl QueryDispatcher for CustomShapeDispatcher {
    fn distance(
        &self,
        pos12: &Isometry<Real>,
        g1: &dyn Shape,
        g2: &dyn Shape,
    ) -> Result<Real, Unsupported> {
        // Try to handle custom shapes
        match (g1.as_any().downcast_ref::<MyShape>(),
               g2.as_any().downcast_ref::<MyShape>()) {
            (Some(s1), Some(s2)) => Ok(custom_distance(s1, s2, pos12)),
            _ => Err(Unsupported), // Let the next dispatcher handle it
        }
    }
    // ... other methods return Err(Unsupported)
}

// Chain: try custom first, fall back to default
let dispatcher = CustomShapeDispatcher.chain(DefaultQueryDispatcher);

// This will use CustomShapeDispatcher if both are MyShape,
// otherwise DefaultQueryDispatcher handles it
let dist = dispatcher.distance(&pos12, shape1, shape2)?;

§Performance Note

Chaining has minimal overhead - it’s just two function calls in the worst case. The first dispatcher is always tried first, so place your most likely-to-succeed dispatcher at the front of the chain for best performance.

§Multiple Chains

You can chain more than two dispatchers by chaining chains:

let dispatcher = custom1
    .chain(custom2)
    .chain(DefaultQueryDispatcher);

This creates a chain of three dispatchers: custom1 -> custom2 -> DefaultQueryDispatcher.

Trait Implementations§

Source§

impl<ManifoldData, ContactData, T, U> PersistentQueryDispatcher<ManifoldData, ContactData> for QueryDispatcherChain<T, U>
where T: PersistentQueryDispatcher<ManifoldData, ContactData>, U: PersistentQueryDispatcher<ManifoldData, ContactData>,

Source§

fn contact_manifolds( &self, pos12: &Isometry<f32>, g1: &dyn Shape, g2: &dyn Shape, prediction: f32, manifolds: &mut Vec<ContactManifold<ManifoldData, ContactData>>, workspace: &mut Option<ContactManifoldsWorkspace>, ) -> Result<(), Unsupported>

Compute all the contacts between two shapes. Read more
Source§

fn contact_manifold_convex_convex( &self, pos12: &Isometry<f32>, g1: &dyn Shape, g2: &dyn Shape, normal_constraints1: Option<&dyn NormalConstraints>, normal_constraints2: Option<&dyn NormalConstraints>, prediction: f32, manifold: &mut ContactManifold<ManifoldData, ContactData>, ) -> Result<(), Unsupported>

Computes the contact-manifold between two convex shapes.
Source§

impl<T, U> QueryDispatcher for QueryDispatcherChain<T, U>

Source§

fn intersection_test( &self, pos12: &Isometry<f32>, g1: &dyn Shape, g2: &dyn Shape, ) -> Result<bool, Unsupported>

Tests whether two shapes are intersecting.
Source§

fn distance( &self, pos12: &Isometry<f32>, g1: &dyn Shape, g2: &dyn Shape, ) -> Result<f32, Unsupported>

Computes the minimum distance separating two shapes. Read more
Source§

fn contact( &self, pos12: &Isometry<f32>, g1: &dyn Shape, g2: &dyn Shape, prediction: f32, ) -> Result<Option<Contact>, Unsupported>

Computes one pair of contact points point between two shapes. Read more
Source§

fn closest_points( &self, pos12: &Isometry<f32>, g1: &dyn Shape, g2: &dyn Shape, max_dist: f32, ) -> Result<ClosestPoints, Unsupported>

Computes the pair of closest points between two shapes. Read more
Source§

fn cast_shapes( &self, pos12: &Isometry<f32>, vel12: &Vector<f32>, g1: &dyn Shape, g2: &dyn Shape, options: ShapeCastOptions, ) -> Result<Option<ShapeCastHit>, Unsupported>

Computes the smallest time when two shapes under translational movement are separated by a distance smaller or equal to distance. Read more
Source§

fn cast_shapes_nonlinear( &self, motion1: &NonlinearRigidMotion, g1: &dyn Shape, motion2: &NonlinearRigidMotion, g2: &dyn Shape, start_time: f32, end_time: f32, stop_at_penetration: bool, ) -> Result<Option<ShapeCastHit>, Unsupported>

Computes the smallest time of impact of two shapes under translational and rotational movement. Read more
Source§

fn chain<U: QueryDispatcher>(self, other: U) -> QueryDispatcherChain<Self, U>
where Self: Sized,

Construct a QueryDispatcher that falls back on other for cases not handled by self

Auto Trait Implementations§

§

impl<T, U> Freeze for QueryDispatcherChain<T, U>
where T: Freeze, U: Freeze,

§

impl<T, U> RefUnwindSafe for QueryDispatcherChain<T, U>

§

impl<T, U> Send for QueryDispatcherChain<T, U>
where T: Send, U: Send,

§

impl<T, U> Sync for QueryDispatcherChain<T, U>
where T: Sync, U: Sync,

§

impl<T, U> Unpin for QueryDispatcherChain<T, U>
where T: Unpin, U: Unpin,

§

impl<T, U> UnwindSafe for QueryDispatcherChain<T, U>
where T: UnwindSafe, U: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.