use std::cmp::Ordering;
#[derive(Debug, PartialEq)]
pub enum Comparison {
Equal,
Sublist,
Superlist,
Unequal,
}
pub fn sublist<T: PartialEq>(first_list: &[T], second_list: &[T]) -> Comparison {
let first_list = first_list.iter();
let second_list = second_list.iter();
match first_list.partial_cmp(second_list) {
Some(Ordering::Equal) => Comparison::Equal,
Some(Ordering::Greater) => Comparison::Superlist,
Some(Ordering::Less) => Comparison::Sublist,
None => Comparison::Unequal,
}
}
Unfortunally this doesn't compile.
The compiler always throws at me an error saying:
error[E0277]: can't compare `T` with `_`
--> src/lib.rs:15:22
|
15 | match first_list.partial_cmp(second_list) {
| ^^^^^^^^^^^ no implementation for `T < _` and `T > _`
|
= note: required because of the requirements on the impl of `PartialOrd<&_>` for `&T`
note: required by a bound in `std::iter::Iterator::partial_cmp`
I'm not really sure what the problem is. Help would be really appreciated Thanks!