Hi folks!
I'm unsure how to annotate the lifetime of the ParseFrom<&str> trait bound in the test function below. I would like to express that the lifetime of the input is independent of the lifetime of the return type.
Also, much more interested in furthering my understanding of Rust here, so if this is not possible, why exactly?
-L
struct ParserErr(pub String);
trait ParseFrom<I> : Sized {
fn parse_from(from: I) -> Result<Self,ParserErr>;
}
/*
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> src/main.rs:19:21
|
19 | fn test<T:ParseFrom<&str>>(from: String) -> Result<T,ParserErr> {
| ^ explicit lifetime name needed here
*/
fn test<T:ParseFrom<&str>>(from: String) -> Result<T,ParserErr> {
T::parse_from(from.as_ref())
}
fn main() {
}
Playground: Rust Playground