Decimal to Binary in Rust
isn't it better to write input as a macro ?


No. At best it might work as a generic function.


  how can i write to_binary as pure function ?


It already is a pure function, it doesn't mutate or depend on external state


  wouldn't be better to return binary type from to_binary instead i32


You should return a String. Converting to i32 is pretty weird. The numbers inside i32 are already in binary. The point of a to_binary function is pretty much always because you for some reason want a textual representation in binary.

As a quick side note, Rust already has the ability to convert values to binary:

format!("{:b}", value);


Your to_binary function would be a bit simpler if build a Vec or Vec  and then converted that instead of building a String.