use crate::shard::GeoShard;
use serde::{Deserialize, Serialize};
pub type ObjectIdentifier = u64;
pub type LatLngCoord = [f64; 2];
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Serialize, Clone, PartialEq)]
pub struct Neighbor {
pub distance: f64,
pub key: String,
}
#[derive(Debug)]
pub enum GeoShardError {
IndexAlreadyExists(String),
IndexNotFound(String),
GeohashError(geohash::GeohashError),
}
impl std::fmt::Display for GeoShardError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
GeoShardError::IndexAlreadyExists(index) => {
write!(f, "Index '{}' already exists.", index)
}
GeoShardError::IndexNotFound(index) => write!(f, "Index '{}' not found.", index),
GeoShardError::GeohashError(err) => write!(f, "Geohash error: {}", err),
}
}
}
impl std::error::Error for GeoShardError {}
#[derive(Clone, Debug, Deserialize)]
pub struct GeoShardConfig {
pub insert_depth: Option<usize>,
pub search_depth: Option<usize>,
pub default_count: Option<usize>,
pub default_sorted: Option<bool>,
}
impl Default for GeoShardConfig {
fn default() -> Self {
GeoShardConfig {
insert_depth: Some(GeoShard::DEFAULT_DEPTH),
search_depth: Some(GeoShard::DEFAULT_DEPTH),
default_count: Some(GeoShard::DEFAULT_COUNT),
default_sorted: Some(GeoShard::DEFAULT_SORTED),
}
}
}
pub type BatchOutput<A, E> = (Vec<(String, A)>, Vec<(String, E)>);