#[repr(transparent)]pub struct Adapt<T>(pub T);Expand description
Shape-only adapter wrapper.
#[repr(transparent)] so &Adapt<T> is layout-compatible with
&T — no boxing, no allocation, the wrapper is purely a place to
hang trait impls that coherence wouldn’t allow on T directly.
Defaults to Cs = Cartesian for every shape this crate adapts.
Compose with WithCs<T, Cs> to re-tag with a
different coordinate system.
Mirrors boost/geometry/geometries/adapted/{c_array, std_array, boost_tuple}.hpp collectively.
§Coordinate system default — silent-Cartesian warning
Adapt<T> defaults to Cartesian.
This matters for adapted containers like [lat, lon] arrays or
(lat, lon) tuples — by default the library will compute
Cartesian Pythagorean distances over them, not great-circle
distances. If your coordinates are spherical or geographic, wrap
them with WithCs:
use geometry_adapt::{Adapt, WithCs};
use geometry_cs::{Degree, Geographic};
// WRONG — treats lon/lat as Cartesian, returns nonsense for distance.
let p = Adapt([4.9_f64, 52.4]);
// RIGHT — the Cs is in the type; distance() picks the right strategy
// (haversine / andoyer / vincenty) and Pythagoras refuses to compile.
let p = WithCs::<_, Geographic<Degree>>::new(Adapt([4.9_f64, 52.4]));The matching compile-time diagnostic that catches a bare
Adapt<[lat, lon]> from reaching Pythagoras lives on
SameAs — see proposal §3.7 and §8 for
the rationale and the mitigations.
§Borrowed arrays — read only
Adapt<&[T; N]> works just like Adapt<[T; N]> for the
read-only algorithm surface (distance, length, area, …),
without copying the storage. The borrow does not implement
PointMut, so any algorithm that needs to output a Point
(e.g. envelope) is a compile error — own your array if you
need mutation.
use geometry_adapt::Adapt;
use geometry_algorithm::distance;
let a_storage = [0.0_f64, 0.0];
let b_storage = [3.0_f64, 4.0];
assert_eq!(distance(&Adapt(&a_storage), &Adapt(&b_storage)), 5.0);Tuple Fields§
§0: T