#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(target_os = "android")]
use android_logger::Config;
pub mod algorithms;
pub mod deviation_detection;
pub mod models;
pub mod navigation_controller;
pub mod navigation_session;
pub mod routing_adapters;
pub mod simulation;
#[cfg(test)]
pub(crate) mod test_utils;
#[cfg(target_os = "android")]
fn init_logger() {
android_logger::init_once(
Config::default()
.with_max_level(log::LevelFilter::Trace)
.with_tag("ferrostar.core"),
);
log::info!("Ferrostar android logger initialized");
}
#[cfg(not(target_os = "android"))]
fn init_logger() {
}
#[cfg(feature = "uniffi")]
#[uniffi::export]
pub fn create_ferrostar_logger() {
init_logger();
}
#[cfg(feature = "uniffi")]
mod uniffi_deps {
pub use crate::models::{Route, Waypoint};
pub use crate::routing_adapters::{
RouteRequestGenerator, RouteResponseParser,
error::{InstantiationError, ParsingError},
osrm::{
OsrmResponseParser,
models::{Route as OsrmRoute, Waypoint as OsrmWaypoint},
},
valhalla::ValhallaHttpRequestGenerator,
};
pub use chrono::{DateTime, Utc};
pub use std::{str::FromStr, sync::Arc};
pub use uniffi::deps::anyhow::anyhow;
pub use uuid::Uuid;
}
#[cfg(feature = "uniffi")]
#[allow(clippy::wildcard_imports)]
use uniffi_deps::*;
#[cfg(feature = "uniffi")]
uniffi::setup_scaffolding!();
#[cfg(feature = "uniffi")]
uniffi::custom_type!(Uuid, String, {
remote,
try_lift: |val| {
Ok(Uuid::from_str(&val)?)
},
lower: |obj| {
obj.to_string()
}
});
#[cfg(feature = "uniffi")]
type UtcDateTime = DateTime<Utc>;
#[cfg(feature = "uniffi")]
uniffi::custom_type!(UtcDateTime, i64, {
remote,
try_lift: |val| {
DateTime::<Utc>::from_timestamp_millis(val).ok_or(anyhow!("Timestamp {val} out of range"))
},
lower: |obj| {
obj.timestamp_millis()
}
});
#[cfg(feature = "uniffi")]
#[uniffi::export]
fn create_valhalla_request_generator(
endpoint_url: String,
profile: String,
options_json: Option<String>,
) -> Result<Arc<dyn RouteRequestGenerator>, InstantiationError> {
Ok(Arc::new(ValhallaHttpRequestGenerator::with_options_json(
endpoint_url,
profile,
options_json.as_deref(),
)?))
}
#[cfg(feature = "uniffi")]
#[uniffi::export]
fn create_osrm_response_parser(polyline_precision: u32) -> Arc<dyn RouteResponseParser> {
Arc::new(OsrmResponseParser::new(polyline_precision))
}
#[cfg(feature = "uniffi")]
#[uniffi::export]
fn create_route_from_osrm(
route_data: &[u8],
waypoint_data: &[u8],
polyline_precision: u32,
) -> Result<Route, ParsingError> {
let route: OsrmRoute = serde_json::from_slice(route_data)?;
let waypoints: Vec<OsrmWaypoint> = serde_json::from_slice(waypoint_data)?;
Route::from_osrm(&route, &waypoints, polyline_precision)
}
#[cfg(feature = "uniffi")]
#[uniffi::export]
fn create_route_from_osrm_route(
route_data: &[u8],
waypoints: &[Waypoint],
polyline_precision: u32,
) -> Result<Route, ParsingError> {
let route: OsrmRoute = serde_json::from_slice(route_data)?;
Route::from_osrm_with_standard_waypoints(&route, waypoints, polyline_precision)
}