#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GeoArgShape {
Geometry1,
Geometry2,
Geometry2Distance,
GeometryBuffer,
LngLat,
LngLatZ,
LngLatPrecision,
LatLngResolution,
Text1,
TextSrid,
BytesSrid,
Haversine4,
Circle,
Bbox,
PointsVariadic,
RingsVariadic,
}
impl GeoArgShape {
pub const fn arity(self) -> (usize, usize) {
match self {
Self::Geometry1 | Self::Text1 => (1, 1),
Self::TextSrid | Self::BytesSrid => (1, 2),
Self::Geometry2 | Self::LngLat => (2, 2),
Self::GeometryBuffer | Self::LngLatZ | Self::LngLatPrecision => (2, 3),
Self::Geometry2Distance | Self::LatLngResolution => (3, 3),
Self::Circle => (3, 4),
Self::Haversine4 | Self::Bbox => (4, 4),
Self::PointsVariadic => (2, MAX_VARIADIC),
Self::RingsVariadic => (1, MAX_VARIADIC),
}
}
}
pub const MAX_VARIADIC: usize = 255;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GeoReturn {
Bool,
Float,
Int,
Text,
Geometry,
Object,
Array,
}
#[derive(Debug, Clone, Copy)]
pub struct GeoFunctionSpec {
pub canonical: &'static str,
pub aliases: &'static [&'static str],
pub args: GeoArgShape,
pub returns: GeoReturn,
}
impl GeoFunctionSpec {
pub fn names(&self) -> impl Iterator<Item = &'static str> + '_ {
std::iter::once(self.canonical).chain(self.aliases.iter().copied())
}
pub fn matches(&self, name: &str) -> bool {
self.canonical == name || self.aliases.contains(&name)
}
}
pub(super) const fn f(
canonical: &'static str,
aliases: &'static [&'static str],
args: GeoArgShape,
returns: GeoReturn,
) -> GeoFunctionSpec {
GeoFunctionSpec {
canonical,
aliases,
args,
returns,
}
}