I have a trait that's defined like this:
use serde::{Deserialize, Serialize};
trait MyTrait {
type InputDoc: Deserialize; //Error: missing lifetime specifier: expected lifetime parameter
type OutputDoc: Serialize;
fn create() -> Self;
fn process(& self, doc: &Self::InputDoc) -> Self::OutputDoc;
}
I want to use the trait like this:
fn run<M: MyTrait>() -> () {
let mytrait = M::create();
let data = ...load some string from somewhere ...;
let doc: serde_json::Result<M::InputDoc> = serde_json::from_str(data);
let result = mytrait.process(&doc);
}
The problem looks similar to this question, but I could not get it to work with the proposed solution. I actually don't get why the lifetime is needed at all, which makes it even harder to figure out the solution. Can somebody explain how to specify a lifetime, that allows my example to work?