Skip to content

Commit 7271fa4

Browse files
committed
Rename Document trait to IndexConfig
1 parent 378737f commit 7271fa4

File tree

5 files changed

+37
-37
lines changed

5 files changed

+37
-37
lines changed

examples/web_app/src/document.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct Crate {
1313
version: String,
1414
}
1515

16-
// Implement the Document trait so that we can use our struct with Meilisearch
16+
// Implement the IndexConfig trait so that we can use our struct with Meilisearch
1717
fn get_readable_download_count(this: &Map<String, Value>) -> String {
1818
if let Some(downloads) = this["downloads"].as_f64() {
1919
if downloads < 1000.0 {

meilisearch-index-setting-macro/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use quote::quote;
66
use syn::parse_macro_input;
77
use syn::spanned::Spanned;
88

9-
#[proc_macro_derive(Document, attributes(document))]
9+
#[proc_macro_derive(IndexConfig, attributes(index_config))]
1010
pub fn generate_index_settings(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
1111
let ast = parse_macro_input!(input as syn::DeriveInput);
1212

@@ -21,13 +21,13 @@ pub fn generate_index_settings(input: proc_macro::TokenStream) -> proc_macro::To
2121

2222
let struct_ident = &ast.ident;
2323

24-
let document_implementation = get_document_implementation(struct_ident, fields);
24+
let index_config_implementation = get_index_config_implementation(struct_ident, fields);
2525
proc_macro::TokenStream::from(quote! {
26-
#document_implementation
26+
#index_config_implementation
2727
})
2828
}
2929

30-
fn get_document_implementation(
30+
fn get_index_config_implementation(
3131
struct_ident: &syn::Ident,
3232
fields: &syn::Fields,
3333
) -> proc_macro2::TokenStream {
@@ -111,7 +111,7 @@ fn get_document_implementation(
111111

112112
quote! {
113113
#[::meilisearch_sdk::macro_helper::async_trait]
114-
impl ::meilisearch_sdk::documents::Document for #struct_ident {
114+
impl ::meilisearch_sdk::documents::IndexConfig for #struct_ident {
115115
const INDEX_STR: &'static str = #index_name;
116116

117117
fn generate_settings() -> ::meilisearch_sdk::settings::Settings {
@@ -144,7 +144,7 @@ fn extract_all_attr_values(
144144
for attr in attrs {
145145
match attr.parse_meta() {
146146
std::result::Result::Ok(syn::Meta::List(list)) => {
147-
if !list.path.is_ident("document") {
147+
if !list.path.is_ident("index_config") {
148148
continue;
149149
}
150150
for token_stream in attr.tokens.clone().into_iter() {
@@ -189,7 +189,7 @@ fn extract_all_attr_values(
189189
syn::Error::new(
190190
ident.span(),
191191
format!(
192-
"Property `{ident}` does not exist for type `document`"
192+
"Property `{ident}` does not exist for type `index_config`"
193193
),
194194
)
195195
.to_compile_error(),

src/documents.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use async_trait::async_trait;
22
use serde::{de::DeserializeOwned, Deserialize, Serialize};
33

4-
/// Derive the [`Document`](crate::documents::Document) trait.
4+
/// Derive the [`IndexConfig`](crate::documents::IndexConfig) trait.
55
///
66
/// ## Field attribute
7-
/// Use the `#[document(..)]` field attribute to generate the correct settings
7+
/// Use the `#[index_config(..)]` field attribute to generate the correct settings
88
/// for each field. The available parameters are:
99
/// - `primary_key` (can only be used once)
1010
/// - `distinct` (can only be used once)
@@ -19,22 +19,22 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
1919
/// ## Sample usage:
2020
/// ```
2121
/// use serde::{Serialize, Deserialize};
22-
/// use meilisearch_sdk::documents::Document;
22+
/// use meilisearch_sdk::documents::IndexConfig;
2323
/// use meilisearch_sdk::settings::Settings;
2424
/// use meilisearch_sdk::indexes::Index;
2525
/// use meilisearch_sdk::client::Client;
2626
///
27-
/// #[derive(Serialize, Deserialize, Document)]
27+
/// #[derive(Serialize, Deserialize, IndexConfig)]
2828
/// struct Movie {
29-
/// #[document(primary_key)]
29+
/// #[index_config(primary_key)]
3030
/// movie_id: u64,
31-
/// #[document(displayed, searchable)]
31+
/// #[index_config(displayed, searchable)]
3232
/// title: String,
33-
/// #[document(displayed)]
33+
/// #[index_config(displayed)]
3434
/// description: String,
35-
/// #[document(filterable, sortable, displayed)]
35+
/// #[index_config(filterable, sortable, displayed)]
3636
/// release_date: String,
37-
/// #[document(filterable, displayed)]
37+
/// #[index_config(filterable, displayed)]
3838
/// genres: Vec<String>,
3939
/// }
4040
///
@@ -45,15 +45,15 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
4545
/// let index: Index = Movie::generate_index(&client).await.unwrap();
4646
/// }
4747
/// ```
48-
pub use meilisearch_index_setting_macro::Document;
48+
pub use meilisearch_index_setting_macro::IndexConfig;
4949

5050
use crate::settings::Settings;
5151
use crate::tasks::Task;
5252
use crate::Client;
5353
use crate::{errors::Error, indexes::Index};
5454

5555
#[async_trait]
56-
pub trait Document {
56+
pub trait IndexConfig {
5757
const INDEX_STR: &'static str;
5858

5959
fn index(client: &Client) -> Index {
@@ -302,7 +302,7 @@ impl<'a> DocumentsQuery<'a> {
302302
mod tests {
303303
use super::*;
304304
use crate::{client::*, indexes::*};
305-
use ::meilisearch_sdk::documents::Document;
305+
use ::meilisearch_sdk::documents::IndexConfig;
306306
use meilisearch_test_macro::meilisearch_test;
307307
use serde::{Deserialize, Serialize};
308308

@@ -313,24 +313,24 @@ mod tests {
313313
}
314314

315315
#[allow(unused)]
316-
#[derive(Document)]
316+
#[derive(IndexConfig)]
317317
struct MovieClips {
318-
#[document(primary_key)]
318+
#[index_config(primary_key)]
319319
movie_id: u64,
320-
#[document(distinct)]
320+
#[index_config(distinct)]
321321
owner: String,
322-
#[document(displayed, searchable)]
322+
#[index_config(displayed, searchable)]
323323
title: String,
324-
#[document(displayed)]
324+
#[index_config(displayed)]
325325
description: String,
326-
#[document(filterable, sortable, displayed)]
326+
#[index_config(filterable, sortable, displayed)]
327327
release_date: String,
328-
#[document(filterable, displayed)]
328+
#[index_config(filterable, displayed)]
329329
genres: Vec<String>,
330330
}
331331

332332
#[allow(unused)]
333-
#[derive(Document)]
333+
#[derive(IndexConfig)]
334334
struct VideoClips {
335335
video_id: u64,
336336
}
@@ -449,17 +449,17 @@ mod tests {
449449

450450
Ok(())
451451
}
452-
#[derive(Serialize, Deserialize, Document)]
452+
#[derive(Serialize, Deserialize, IndexConfig)]
453453
struct Movie {
454-
#[document(primary_key)]
454+
#[index_config(primary_key)]
455455
movie_id: u64,
456-
#[document(displayed, searchable)]
456+
#[index_config(displayed, searchable)]
457457
title: String,
458-
#[document(displayed)]
458+
#[index_config(displayed)]
459459
description: String,
460-
#[document(filterable, sortable, displayed)]
460+
#[index_config(filterable, sortable, displayed)]
461461
release_date: String,
462-
#[document(filterable, displayed)]
462+
#[index_config(filterable, displayed)]
463463
genres: Vec<String>,
464464
}
465465
}

src/dumps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//!
77
//! During a [dump export](Client::create_dump), all [indexes](crate::indexes::Index) of the current instance are exported—together with their documents and settings—and saved as a single `.dump` file.
88
//!
9-
//! During a dump import, all indexes contained in the indicated `.dump` file are imported along with their associated [documents](crate::document::Document) and [settings](crate::settings::Settings).
9+
//! During a dump import, all indexes contained in the indicated `.dump` file are imported along with their associated [index_configs](crate::document::IndexConfig) and [settings](crate::settings::Settings).
1010
//! Any existing [index](crate::indexes::Index) with the same uid as an index in the dump file will be overwritten.
1111
//!
1212
//! Dump imports are [performed at launch](https://docs.meilisearch.com/reference/features/configuration.html#import-dump) using an option.

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
pub mod client;
228228
/// Module representing the [documents] structures.
229229
pub mod documents;
230-
/// Module containing the [document::Document] trait.
230+
/// Module containing the [document::IndexConfig] trait.
231231
pub mod dumps;
232232
/// Module containing the [errors::Error] struct.
233233
pub mod errors;
@@ -252,7 +252,7 @@ mod utils;
252252
pub use client::*;
253253

254254
#[cfg(test)]
255-
/// Support for the `Document` derive proc macro in the crate's tests
255+
/// Support for the `IndexConfig` derive proc macro in the crate's tests
256256
extern crate self as meilisearch_sdk;
257257
/// Can't assume that the user of proc_macro will have access to `async_trait` crate. So exporting the `async-trait` crate from `meilisearch_sdk` in a hidden module.
258258
#[doc(hidden)]

0 commit comments

Comments
 (0)