Closed
Description
Try this snippet: playground
pub fn strip_prefix<'a, T>(s: &'a [T], prefix: &[T]) -> Option<&'a [T]>
// where
// T: PartialEq
{
let n = prefix.len();
if n <= s.len() {
let (head, tail) = s.split_at(n);
if head == prefix {
return Some(tail);
}
}
None
}
The compiler errors out:
error[E0369]: binary operation `==` cannot be applied to type `&[T]`
--> src/lib.rs:8:17
|
8 | if head == prefix {
| ---- ^^ ------ &[T]
| |
| &[T]
error: aborting due to previous error
For more information about this error, try `rustc --explain E0369`.
It would be nice if the compiler could suggest adding PartialEq
bound for T
.