To find the midpoint between two points in Rust, you can use the following code:
main.rs395 chars21 lines
Here, we define a Point
struct with x
and y
coordinates, and an implementation that defines a midpoint
method that returns a new Point
at the midpoint between itself and another Point
.
In the main function, we create two points p1
and p2
, find their midpoint using the midpoint
method, and print the result.
gistlibby LogSnag