Skip to content

[ENHANCEMENT] Provide non-array based SearchParts for searching single a index #149

Open
@oeed

Description

@oeed

Is your feature request related to a problem? Please describe.
95% of my queries are only ever on a single index and I've found it a bit difficult/unergonomic to try and search for these when they're not 'static. Because SearchParts::Index takes &[&str] you have to wrap the single string like &[my_str], which doesn't work in situation where you return the SearchParts by value, not reference, like this (it's a bit of a contrived example, but I've run in to it in various situations):

pub trait Index {
  fn name(&self) -> &str;

  fn search_parts<'a>(&'a self) -> SearchParts<'a> {
    SearchParts::Index(&[self.name()])
  }
}

You get a cannot return value referencing temporary value, returns a value referencing data owned by the current function error. My index names are dynamic and so can't be static, this becomes an issue because the variant requires a reference to an array of references, which I simply can't figure out how to do within a single struct.

I'm still a bit new to Rust though, so if there's actually a good solution to this I'd love to know, I haven't been able to find one though.

Describe the solution you'd like
I'm far from a Rust expert as I've said, so there may be better ways; but the idea that comes to mind is to simply providing additional variants.

i.e.

pub enum SearchParts<'b> {
    ...
    SingleIndex(&'b str)
}

The implementation of SearchParts looks fairly straight forward so I'd be happy to provide a PR if open to the idea.

Describe alternatives you've considered
With a few layers of indirection and nested structs this is possible, but it's rather messy and unergonomic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions