Skip to main content

geometry_algorithm/
dyn_error.rs

1//! Cross-kind mismatch error for the `_dyn` algorithm wrappers.
2//!
3//! Mirrors no single Boost type — Boost would static-assert at
4//! compile time. The Rust port surfaces the same error as a
5//! `Result::Err` once the dispatch is dynamic.
6
7use core::fmt;
8
9use geometry_model::DynKind;
10
11/// Returned by `_dyn` wrappers when the input combination has no
12/// static algorithm impl.
13///
14/// Example: `distance_dyn(&Polygon, &Polygon)` — v1 has no
15/// polygon-to-polygon distance impl yet. The wrapper returns
16/// `Err(DynKindMismatch { got: [Polygon, Polygon], expected: &[...] })`
17/// rather than panicking.
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub struct DynKindMismatch {
20    /// The actual kinds of the inputs, in argument order.
21    pub got: alloc::vec::Vec<DynKind>,
22    /// The kind combinations the algorithm supports. Each inner slice
23    /// is one supported argument list.
24    pub expected: &'static [&'static [DynKind]],
25}
26
27impl fmt::Display for DynKindMismatch {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        write!(
30            f,
31            "dynamic-geometry algorithm received {:?}; supported combinations: {:?}",
32            self.got, self.expected,
33        )
34    }
35}
36
37#[cfg(feature = "std")]
38impl std::error::Error for DynKindMismatch {}