Skip to main content

core/num/
complex.rs

1/// A complex number.
2#[derive(#[automatically_derived]
#[unstable(feature = "complex_numbers", issue = "154023")]
impl<T: crate::clone::Clone> crate::clone::Clone for Complex<T> {
    #[inline]
    fn clone(&self) -> Complex<T> {
        Complex {
            re: crate::clone::Clone::clone(&self.re),
            im: crate::clone::Clone::clone(&self.im),
        }
    }
}Clone, #[automatically_derived]
#[unstable(feature = "complex_numbers", issue = "154023")]
impl<T: crate::marker::Copy> crate::marker::Copy for Complex<T> { }Copy, #[automatically_derived]
#[unstable(feature = "complex_numbers", issue = "154023")]
impl<T: crate::fmt::Debug> crate::fmt::Debug for Complex<T> {
    #[inline]
    fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
        crate::fmt::Formatter::debug_struct_field2_finish(f, "Complex", "re",
            &self.re, "im", &&self.im)
    }
}Debug, #[automatically_derived]
#[unstable(feature = "complex_numbers", issue = "154023")]
impl<T: crate::cmp::PartialEq> crate::marker::StructuralPartialEq for
    Complex<T> {
}
#[automatically_derived]
#[unstable(feature = "complex_numbers", issue = "154023")]
impl<T: crate::cmp::PartialEq> crate::cmp::PartialEq for Complex<T> {
    #[inline]
    fn eq(&self, other: &Complex<T>) -> bool {
        self.re == other.re && self.im == other.im
    }
}PartialEq)]
3#[unstable(feature = "complex_numbers", issue = "154023")]
4#[repr(C)]
5#[lang = "complex"]
6pub struct Complex<T> {
7    /// The real component.
8    pub re: T,
9    /// The imaginary component.
10    pub im: T,
11}
12
13#[unstable(feature = "complex_numbers", issue = "154023")]
14impl<T> Complex<T> {
15    /// Create a new complex number from a real and imaginary component.
16    #[must_use]
17    pub fn new(re: T, im: T) -> Complex<T> {
18        Complex { re, im }
19    }
20}