There are some easy math fuction,there are add...... You can use the add function too add,and use subtract...... There is code: pub mod math_functions { pub fn add(a: i32, b: i32) -> i32 { a + b } pub fn subtract(a: i32, b: i32) -> i32 { a - b } pub fn multiply(a: i32, b: i32) -> i32 { a * b } pub fn divide(a: i32, b: i32) -> Result { if b == 0 { Err("Cannot divide by zero") } else { Ok(a / b) } } } And use distance: fn main(){ let ax: i32 = ......; let ...... ...... println!("{}",distance(ax,ay,bx,by)); }