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