Skip to main content

boxdd_sys/
precision.rs

1/// The native Box2D world-coordinate precision selected for this crate build.
2#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
3pub enum Precision {
4    /// Single-precision world coordinates.
5    Single,
6    /// Double-precision world coordinates for large worlds.
7    Double,
8}
9
10impl Precision {
11    /// The precision selected by this crate's Cargo features.
12    pub const ACTIVE: Self = if cfg!(feature = "double-precision") {
13        Self::Double
14    } else {
15        Self::Single
16    };
17
18    /// Return the stable manifest spelling for this precision.
19    pub const fn as_str(self) -> &'static str {
20        match self {
21            Self::Single => "single",
22            Self::Double => "double",
23        }
24    }
25
26    /// Return whether this is the double-precision ABI.
27    pub const fn is_double(self) -> bool {
28        matches!(self, Self::Double)
29    }
30
31    /// Return the checked-in bindings artifact selected for this ABI.
32    pub const fn pregenerated_bindings_file(self) -> &'static str {
33        match self {
34            Self::Single => "bindings_pregenerated.rs",
35            Self::Double => "bindings_double.rs",
36        }
37    }
38
39    /// Return the stable WASM provider import module for this ABI.
40    pub const fn wasm_import_module(self) -> &'static str {
41        match self {
42            Self::Single => "box2d-sys-v2-single",
43            Self::Double => "box2d-sys-v2-double",
44        }
45    }
46}
47
48/// Marker type for the single-precision native ABI.
49#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
50pub struct SinglePrecision;
51
52/// Marker type for the double-precision native ABI.
53#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
54pub struct DoublePrecision;
55
56/// Marker type for the native ABI selected by this crate build.
57#[cfg(not(feature = "double-precision"))]
58pub type ActivePrecision = SinglePrecision;
59
60/// Marker type for the native ABI selected by this crate build.
61#[cfg(feature = "double-precision")]
62pub type ActivePrecision = DoublePrecision;
63
64/// Compile-time identity of the selected native ABI.
65pub const ABI_PRECISION: Precision = Precision::ACTIVE;
66
67/// Whether this crate was compiled for the double-precision native ABI.
68pub const IS_DOUBLE_PRECISION: bool = ABI_PRECISION.is_double();