-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'static lifetimes in operations #102
Comments
Thanks for the notification. Do you have a larger example that demonstrates the problem? Perhaps something I can encapsulate in a test case? In a simple case, using something like: const INDEX_NAME: &'static str = "my_index";
fn test() {
let mut client = create_client();
client.index(INDEX_NAME, "type").with_doc(&make_document()).send();
} works as you'd expect, because the lifetime is self-contained and all the parameters exceed what's required. But in your case you're returning the I expect the solution will be the same in all cases, but it would be good to have a reproducible test or example code to verify it. |
Here is example of code: extern crate rs_es;
extern crate serde;
use rs_es::Client;
use rs_es::operations::index::IndexOperation;
use serde::Serialize;
const INDEX_NAME: &'static str = "my_index";
struct Wrapper(Client);
impl Wrapper {
fn get_index_operation<'a, 'b, T: Serialize>(&self, doc: &'b T) -> &'a mut IndexOperation<'a, 'b, T> {
self.0.index(INDEX_NAME, "type").with_doc(doc)
}
}
fn main() { } How can i set lifetimes to make it compile? Now it says:
|
Hi, in my case, i need to use
&'static str
for index and doc type, but lifetimes inIndexOperation
in 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_doc
accepts&'b E
(in our case&'static E
) and passingdoc: &'b T
for 'b != 'static breaks borrow checker rulesFor now, possible solution can be using
mem::transmute
to avoid this lifetime rules.The text was updated successfully, but these errors were encountered: