Skip to content

Extend Document trait with function to get index #444

Closed
@amaihoefner

Description

@amaihoefner

Description
Add a index() function to the Document trait to make it easier to get access to the index.

Basic example
Right now, something that implments Into<String> needs to be provided when one wants to get access to an index:

let movie_index = client.index("movies");

With this change one could instead write:

let movie_index = Movie::index(&client);

(Provided Movie implements the Document trait)
This way accessing an index becomes less prone to typos and one would'nt have to keep track of the name of the index, only the associated struct.

Other
It might also make sense to add a constant INDEX_STR to the trait.
This would have the following benefits:

  • it could be used to provide a default implementation for the proposed Document::index function
  • it could be used when implementing Document::generate_index by hand

Adding this to the derive macro would also not require much effort, as the index name is already being extracted there.

I will provide a draft merge request with these changes to act as a base for further discussion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions