ferrostar 0.49.0

The core of modern turn-by-turn navigation.
Documentation
#[cfg(feature = "alloc")]
use alloc::string::{String, ToString};

// TODO: This implementation seems less than ideal. In particular, it hides what sort of JSON error occurred due to an apparent bug in UniFFI.
// The trouble appears to be with generating "flat" enum bindings that are used with callback
// interfaces when the underlying actually has fields.
#[derive(Debug, thiserror::Error)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Error))]
pub enum InstantiationError {
    #[error("Error parsing the JSON options for the request.")]
    OptionsJsonParseError,
}

// TODO: See comment above
#[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 {
    // TODO: Unable to find route and other common errors
    #[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(),
        }
    }
}