I am trying to implement my own version of Complex (purely for my own knowledge). I am trying to have the division operation implemented. But I am having trouble comparing the denominator with 0 value of corresponding type. How do I do that? Basically if the division is by 0 I want to return my own error.

I mean, the zero value of i_ is 0 (where _ is 8, 32, 64 etc) and the zero value of f_ is 0.0 (_ is 32 or 64). Also my below implementation does not stop me from using &str as a type. How can I restrict the Complex to be only of numeric type?

What traits does a number have? If you need to be able to compare to 0, then the type would have to be able to convert From<u8> and be comparable, at least being able to check for equality (PartialEq, Eq). There are also the traits Add, Sub, Mul and Div. As long as a type implements all those traits, it doesn't matter, if it's a number or something else, does it? For convenience, you want to create a trait, that covers all these properties and auto-implement the trait for all types that meet these requirements.

trait Number: From<u8> + PartialEq + Add + Sub + Mul + Div {}
impl<T> Number for T where T: From<u8> + PartialEq + Add + Sub + Mul + Div {}

Then you can simply write T: Number as a type requirement for your complex number.

Unfortunately, division of complex numbers doesn't work this way — it's more complex than dividing real and imaginary parts separately. Moreover, the notation x / y usually returns the number directly (as opposed to use a Result), and it's recommended to keep custom implementations of Div consistent with that.

You are right. But I wanted to start simple. Basically the complicated formula comes down to same a/b, c/d.
where b = d = norm_sqrt() = 0. only possible if b and d are 0. (hopefully).

By the way, you can use the edit button under each of your first two posts in this thread to add the two lines of backticks that will cause those already-written posts to display their Rust code formatted properly. I almost stopped reading this thread when I came across the second of those unformatted posts; it's just not worth the time to try to puzzle out that unformatted code.