Trying to abstract some algorithm where I only need Set operations I write
use std::collections::HashSet;
trait Set<T> {
fn insert(self: &mut Self, item: T);
fn contains(self: &Self, item: T) -> bool;
}
impl<T> Set<T> for HashSet<T> {
fn insert(&mut self, item: T) {
self.insert(item);
}
fn contains(&self, item: T) -> bool {
self.contains(item)
}
}
impl<T> Set<T> for Vec<T> {
fn insert(&mut self, item: T) {
self.push(item);
}
fn contains(&self, item: T) -> bool {
self.contains(item)
}
}
I get warning about recursion at compile time, while I "obviously" don't want to recurse but use the underlying implementation on the implementer.
function cannot return without recursing
cannot return without recursing
note: `#[warn(unconditional_recursion)]` on by default
help: a `loop` may express intention better if this is on purposerustc(unconditional_recursion)
I would have expected recursion to happen only if specified (self as Set<T>).insert
What is the idiomatic way to go around that ?