I created a function in a sample rust project that compares two values of types that implement the PartialOrd trait. It isn’t compiling. Below is the sample code:
fn main(){
let x: i32 = 5;
let y: i32 = 6;
dbg!(greater_than(&x, &y));
}
fn greater_than(x: &impl PartialOrd, y: &impl PartialOrd) -> bool{
x > y
}
I am using RustRover IDE (EAP). I also use Vs code. I am getting the error below
My understanding is that once in your parameters in your function signature were typed using the impl trait syntax, any type that implement that trait (i32 is meant to implement PartialOrd trait) could be used in the function as an argument. (I have used a different function signature -using trait bounds as shown below- and it worked fine):
fn greater_than<T: PartialOrd>(x: &T, y: &T) -> bool
1