Description
Issue
Currently the requested attributes are passed to search functions as &Vec<&str>>
. This is somewhat restrictive as it forces you to use a Vec.
Where it really becomes a problem is in streaming searches. The vec has to stay alive for the duration of the stream, which makes it difficult to satisfy the borrow checker.
There's this pretty neat function in serde_aux
that almost solves the issue: serde_introspect()
It returns a static reference to the struct field names, which is exactly what you want in the attributes argument. However it's not a Vec, so you need to do something like this:
// Save the attributes to a lazily initialized static vec.
static ATTRIBUTES: Lazy<Vec<&'static str>> = Lazy::new(||
serde_introspect::<ResultType>().to_vec()
);
// It being static means that it can be referenced here.
let stream = client.streaming_search_paged(search_base, scope, &*SEARCH_FILTER, &ATTRIBUTES, 250).await?;
return Ok(stream)
Solution
Simple
A simple solution would be to change the argument to just not be a vec, something like the AsRef
thing used in ldap3
, making sure it's compatible with serde_aux::serde_introspect()
.
A nicer solution
Note that you always want to just pass the list of struct attribute names as the argument. We could just remove the argument altogether and just call serde_aux::serde_introspect()
internally. Then you'd select the attributes simply by including them in your result type. Would have to be documented.
Metadata
Metadata
Assignees
Labels
Projects
Status