So I have a trait Find
trait Find {
find(&self, haystack: &[u8]) -> Result<usize, ()>
}
and an enum
enum ReadUntil<T: Find> {
Parser(T),
LastNewLine,
}
and a function read_until
fn read_until<T: Find>(&mut self, needle: &ReadUntil<T>, ...) -> Result<> {
...
...
...
let k = match needle {
ReadUntil::Parser(ref parser) => parser.find(search_buf.unwrap_or(&[])),
ReadUntil::LastNewLine => search_buf.ok_or(()).map(|b| b.len()),
};
...
...
...
}
However, It appears that I am unable to pass ReadUntil::LastNewLine
I get this error,
cannot infer type for type parameter `T` declared on the enum `ReadUntil`
I am unsure of how to proceed. How are able to use None
with Option<T>
but I can't use LastNewLine
. I assume it has to do with the trait bounds on the function? Is that correct? I'd like to enforce that trait bound but also be able to pass in ReadUntil::LastNewLine
.