inejge / ldap3

A pure-Rust LDAP library using the Tokio stack
Apache License 2.0
226 stars 39 forks source link

[Question] [0.7-alpha] Why search needs `'static`? #48

Closed Geobert closed 4 years ago

Geobert commented 4 years ago

Hi,

Among the incoming changes with 0.7, I noticed that LdapConn::search now needs 'static lifetime for attrs, why is that? Doesn't that make the whole function unusable?

I have an internal test tool that receive the parameters from a script, so my attrs are not 'static per se even if they live the whole program lifetime. Or maybe (and probably) I'm missing something?

inejge commented 4 years ago

S: 'static includes owned types like String, so you can pass a vector of Strings as attrs (but not a vector of references to Strings). If you have a vector of &strs of unknown provenance, you need to turn it into a vector of Strings.

The S: 'static bound is needed because of the addition of search adapters, which are trait objects and come with the 'static bound by default. Trying to relax the bound is complicated because of the need to sling the Future-implementing structs between threads, and I'm not sure that it can be done at all.

Geobert commented 4 years ago

I didn't know about String being 'static! Thanks!

I indeed have a Vec<&'a str> because the script AST stays in memory the whole time.

inejge commented 4 years ago

I found the way to relax the 'static bound, so references can be used again in the attr vector. It required a bit of fiddling with lifetimes, but so far it seems to work.