I wrote some code that compiled fine, then I turned T into Option<T> and now I'm getting this error:
error[E0308]: mismatched type...one type is more general than the other
When building a minimal case I noticed that if I change data: &str into data: String the code compiles fine again.
pub trait Subscriber {
fn recv(&mut self, data: &str);
}
pub struct Task<T>(pub Option<T>)
where
T: Fn(&str);
impl<T> Subscriber for Task<T>
where
T: Fn(&str),
{
fn recv(&mut self, data: &str) {
self.0.take().unwrap()(data)
}
}
fn main() {
Task(Some(|_| ()));
}
Can someone help me understand what's going on here?