#[cfg(feature = "alloc")]
use alloc::string::{String, ToString};
#[derive(Debug, thiserror::Error)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Error))]
pub enum InstantiationError {
#[error("Error parsing the JSON options for the request.")]
OptionsJsonParseError,
}
#[derive(Debug, thiserror::Error)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Error))]
pub enum RoutingRequestGenerationError {
#[error("Too few waypoints were provided to compute a route.")]
NotEnoughWaypoints,
#[error("Error generating JSON for the request.")]
JsonError,
#[error("An unknown error generating a request was raised in foreign code.")]
UnknownRequestGenerationError,
}
#[cfg(feature = "uniffi")]
impl From<uniffi::UnexpectedUniFFICallbackError> for RoutingRequestGenerationError {
fn from(_: uniffi::UnexpectedUniFFICallbackError) -> RoutingRequestGenerationError {
RoutingRequestGenerationError::UnknownRequestGenerationError
}
}
impl From<serde_json::Error> for InstantiationError {
fn from(_: serde_json::Error) -> Self {
InstantiationError::OptionsJsonParseError
}
}
impl From<serde_json::Error> for RoutingRequestGenerationError {
fn from(_: serde_json::Error) -> Self {
RoutingRequestGenerationError::JsonError
}
}
#[derive(Debug, thiserror::Error)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Error))]
pub enum ParsingError {
#[error("Failed to parse route json object: {error}.")]
InvalidRouteObject { error: String },
#[error("Failed to parse route geometry: {error}.")]
InvalidGeometry { error: String },
#[error("Failed to parse annotations: {error}.")]
MalformedAnnotations { error: String },
#[error("Routing adapter returned an unexpected status code: {code}.")]
InvalidStatusCode {
code: String,
description: Option<String>,
},
#[error("An unknown error parsing a response was raised in foreign code.")]
UnknownParsingError,
}
#[cfg(feature = "uniffi")]
impl From<uniffi::UnexpectedUniFFICallbackError> for ParsingError {
fn from(_: uniffi::UnexpectedUniFFICallbackError) -> ParsingError {
ParsingError::UnknownParsingError
}
}
impl From<serde_json::Error> for ParsingError {
fn from(e: serde_json::Error) -> Self {
ParsingError::InvalidRouteObject {
error: e.to_string(),
}
}
}