I am giving my first steps with Rust. I have the following code:
use euclid;
fn main() {
_7();
}
fn _7() {
fn minus<T,U>(a: &euclid::Vector3D<T,U>, b: &euclid::Vector3D<T,U>) -> euclid::Vector3D<T,U> {
let c = a - b;
c
}
enum Unit {}
let a = euclid::Vector3D::<f64, Unit>::new(1.,0.,0.);
let b = euclid::Vector3D::<f64, Unit>::new(1.,1.,0.);
let c = a-b; // I know this works.
dbg!(&c);
}
I wrote it this way considering this:
a
andb
are references, so they are to be borrowed from the "outer scope" and the ownership is not transferred tominus
.c
is created insideminus
so the ownership is there, but it is then returned so the ownership goes to the "outer scope".
However, this gives me
error[E0369]: cannot subtract `&Vector3D<T, U>` from `&Vector3D<T, U>`
Probably the meaning of this is obvious for someone experienced with Rust, but not for me. How should I implement such function?
(I know there is already an implementation of this, but wanna do it to gain understanding, I am playing around.)