Hi, in my case, i need to use &'static str for index and doc type, but lifetimes in IndexOperation in such case, disallow me pass reference to doc with non-static lifetime. What i try to say:
const ES_INDEX_NAME: &'static str = "my_index";
pub trait EsDocument: Serialize + Deserialize {
fn entity_type() -> &'static str;
}
pub fn index<'a, 'b, T>(&'a mut self, doc: &'b T) -> &'a mut IndexOperation<'a, 'b, T>
where T: EsDocument
{
self.client.index(ES_INDEX_NAME, T::entity_type()).with_doc(doc)
}
In this example, lifetime 'b == 'static, because:
fn index<'a, 'b, E: Serialize>(&'a mut self, index: &'b str, doc_type: &'b str) -> IndexOperation<'a, 'b, E>
fn with_doc(&'b mut self, doc: &'b E) -> &'b mut Self
with_doc accepts &'b E (in our case &'static E) and passing doc: &'b T for 'b != 'static breaks borrow checker rules
For now, possible solution can be using mem::transmute to avoid this lifetime rules.
Hi, in my case, i need to use
&'static strfor index and doc type, but lifetimes inIndexOperationin such case, disallow me pass reference to doc with non-static lifetime. What i try to say:In this example, lifetime 'b == 'static, because:
with_docaccepts&'b E(in our case&'static E) and passingdoc: &'b Tfor 'b != 'static breaks borrow checker rulesFor now, possible solution can be using
mem::transmuteto avoid this lifetime rules.