#[cfg(feature = "geo")]
use super::{GeoContext, sensor::GeoSensor};
#[cfg(feature = "geo")]
pub struct StaticOxigdalGeoSensor {
pub bbox: oxigdal_core::BoundingBox,
pub country_code: Option<String>,
}
#[cfg(feature = "geo")]
impl GeoSensor for StaticOxigdalGeoSensor {
fn sense(&self) -> Option<GeoContext> {
let mut ctx = GeoContext::from_oxigdal_bbox(&self.bbox);
if let Some(ref cc) = self.country_code {
ctx = ctx.with_country(cc.clone());
}
Some(ctx)
}
}
#[cfg(feature = "geo")]
pub struct DynamicOxigdalGeoSensor<F>
where
F: Fn() -> Option<oxigdal_core::BoundingBox> + Send + Sync,
{
bbox_fn: F,
country_code: Option<String>,
}
#[cfg(feature = "geo")]
impl<F> DynamicOxigdalGeoSensor<F>
where
F: Fn() -> Option<oxigdal_core::BoundingBox> + Send + Sync,
{
#[must_use]
pub fn new(bbox_fn: F) -> Self {
Self {
bbox_fn,
country_code: None,
}
}
#[must_use]
pub fn with_country_code(mut self, cc: String) -> Self {
self.country_code = Some(cc);
self
}
}
#[cfg(feature = "geo")]
impl<F> GeoSensor for DynamicOxigdalGeoSensor<F>
where
F: Fn() -> Option<oxigdal_core::BoundingBox> + Send + Sync,
{
fn sense(&self) -> Option<GeoContext> {
let bbox = (self.bbox_fn)()?;
let mut ctx = GeoContext::from_oxigdal_bbox(&bbox);
if let Some(ref cc) = self.country_code {
ctx = ctx.with_country(cc.clone());
}
Some(ctx)
}
}