use crate::gaussian_integer::GaussianInteger;
use crate::natural::Natural;
use malachite_base::num::conversion::traits::ConvertibleFrom;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct NaturalFromGaussianIntegerError;
impl TryFrom<GaussianInteger> for Natural {
type Error = NaturalFromGaussianIntegerError;
fn try_from(x: GaussianInteger) -> Result<Self, Self::Error> {
if x.imaginary == 0u32 {
Self::try_from(x.real).map_err(|_| NaturalFromGaussianIntegerError)
} else {
Err(NaturalFromGaussianIntegerError)
}
}
}
impl TryFrom<&GaussianInteger> for Natural {
type Error = NaturalFromGaussianIntegerError;
fn try_from(x: &GaussianInteger) -> Result<Self, Self::Error> {
if x.imaginary == 0u32 {
Self::try_from(&x.real).map_err(|_| NaturalFromGaussianIntegerError)
} else {
Err(NaturalFromGaussianIntegerError)
}
}
}
impl ConvertibleFrom<&GaussianInteger> for Natural {
#[inline]
fn convertible_from(x: &GaussianInteger) -> bool {
x.imaginary == 0u32 && Self::convertible_from(&x.real)
}
}