Hello!
I work on generic query parser for my web-service and got a trouble. This is simplified main function
impl<'a, Q> BeforeMiddleware for QueryParser<Q>
where
Q: QueryKey + Send + Sync,
<Q as Key>::Value: Query + Deserialize<'a>,
{
fn before(&self, request: &mut Request) -> IronResult<()> {
let query_data = qs::from_str(request.url.query().unwrap());
let mut query: Q::Value = query_data.unwrap();
request.extensions.insert::<Q>(query);
Ok(())
}
}
It's not compile because of lifetime conflict. And I understand why - the query() method return &str, then the qs::from_str (serde in fact) parse it and store some parts of the source query string in Q::Value's fields. So Rust can't be sure that the query sting will live as long as result structure. It's correct.
But I store the parse result in the Request object, so it should live as long as the Request itself! Is there some way to explain this to Rust? Or I should use DeserializeOwned?