use thiserror::Error;
#[derive(Debug, Clone, Error, PartialEq, Eq, Copy)]
pub enum SGP4Error {
#[error("Success")]
SGP4Success = 0,
#[error("Eccentricity > 1 or < 0")]
SGP4ErrorEccen = 1,
#[error("Mean motion < 0")]
SGP4ErrorMeanMotion = 2,
#[error("Perturbed Eccentricity > 1 or < 0")]
SGP4ErrorPerturbEccen = 3,
#[error("Semi-Latus Rectum < 0")]
SGP4ErrorSemiLatusRectum = 4,
#[error("Unused")]
SGP4ErrorUnused = 5,
#[error("Orbit Decayed")]
SGP4ErrorOrbitDecay = 6,
}
impl From<i32> for SGP4Error {
fn from(val: i32) -> Self {
match val {
0 => Self::SGP4Success,
1 => Self::SGP4ErrorEccen,
2 => Self::SGP4ErrorMeanMotion,
3 => Self::SGP4ErrorPerturbEccen,
4 => Self::SGP4ErrorSemiLatusRectum,
6 => Self::SGP4ErrorOrbitDecay,
_ => Self::SGP4ErrorUnused,
}
}
}
impl From<SGP4Error> for i32 {
fn from(val: SGP4Error) -> Self {
match val {
SGP4Error::SGP4ErrorEccen => 1,
SGP4Error::SGP4ErrorMeanMotion => 2,
SGP4Error::SGP4ErrorOrbitDecay => 6,
SGP4Error::SGP4ErrorPerturbEccen => 3,
SGP4Error::SGP4ErrorSemiLatusRectum => 4,
SGP4Error::SGP4ErrorUnused => -1,
SGP4Error::SGP4Success => 0,
}
}
}
#[derive(Debug, Error)]
pub enum Error {
#[error("SGP4 init error: {0}")]
SatRecInit(SGP4Error),
#[error(transparent)]
Source(Box<dyn std::error::Error + Send + Sync>),
}
impl Error {
pub fn source<E>(e: E) -> Self
where
E: std::error::Error + Send + Sync + 'static,
{
Self::Source(Box::new(e))
}
}
pub type Result<T> = std::result::Result<T, Error>;