Skip to content

Commit 5615671

Browse files
bors[bot]Adrian Coutsoftidesbrunoocasali
authored
Merge #267
267: fixed formatting with clippy and removed Document trait r=brunoocasali a=irevoire # Pull Request Since `@honne23` doesn't seem available currently, and we have #262, #263, and #264 waiting for this PR to be merged, I took back on it. But thanks a lot, `@honne23;` you wrote most of the code, and I just applied the few left comments. Thanks for contributing! ## What does this PR do? Fixes #255 Closes #261 <!-- Please link the issue you're trying to fix with this PR, if none then please create an issue first. --> ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Adrian Coutsoftides <adrian.coutsoftides-ext@vitrifi.net> Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
2 parents 54e7b7e + 512fd66 commit 5615671

File tree

11 files changed

+139
-376
lines changed

11 files changed

+139
-376
lines changed

.code-samples.meilisearch.yaml

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,11 @@ add_or_replace_documents_1: |-
2929
], None).await.unwrap();
3030
add_or_update_documents_1: |-
3131
// Define the type of our documents
32-
#[derive(Serialize, Deserialize, Debug)]
32+
#[derive(Serialize, Deserialize)]
3333
struct IncompleteMovie {
3434
id: usize,
3535
title: String
3636
}
37-
impl Document for IncompleteMovie {
38-
type UIDType = usize;
39-
fn get_uid(&self) -> &Self::UIDType { &self.id }
40-
}
4137
4238
let task: Task = client.index("movies").add_or_update(&[
4339
IncompleteMovie {
@@ -369,7 +365,6 @@ settings_guide_sortable_1: |-
369365
add_movies_json_1: |-
370366
use meilisearch_sdk::{
371367
indexes::*,
372-
document::*,
373368
client::*,
374369
search::*,
375370
settings::*
@@ -392,15 +387,11 @@ add_movies_json_1: |-
392387
})}
393388
documents_guide_add_movie_1: |-
394389
// Define the type of our documents
395-
#[derive(Serialize, Deserialize, Debug)]
390+
#[derive(Serialize, Deserialize)]
396391
struct IncompleteMovie {
397392
id: String,
398393
title: String
399394
}
400-
impl Document for IncompleteMovie {
401-
type UIDType = String;
402-
fn get_uid(&self) -> &Self::UIDType { &self.id }
403-
}
404395
405396
// Add a document to our index
406397
let task: Task = client.index("movies").add_documents(&[
@@ -412,18 +403,14 @@ documents_guide_add_movie_1: |-
412403
document_guide_create_index_primary_key: |-
413404
client.create_index("movies", Some("reference_number")).await.unwrap();
414405
document_guide_add_document_primary_key: |-
415-
#[derive(Serialize, Deserialize, Debug)]
406+
#[derive(Serialize, Deserialize)]
416407
struct Movie {
417408
id: String,
418409
title: String,
419410
poster: String,
420411
overview: String,
421412
release_date: String
422413
}
423-
impl Document for Movie {
424-
type UIDType = String;
425-
fn get_uid(&self) -> &Self::UIDType { &self.id }
426-
}
427414
428415
let task: Task = client.index("movies").add_documents(&[
429416
Movie {
@@ -447,10 +434,9 @@ getting_started_add_documents_md: |-
447434
```
448435
449436
Documents in the Rust library are strongly typed.
450-
You have to implement the `Document` trait on a struct to be able to use it with Meilisearch.
451437
452438
```rust
453-
#[derive(Serialize, Deserialize, Debug)]
439+
#[derive(Serialize, Deserialize)]
454440
struct Movie {
455441
id: String,
456442
title: String,
@@ -459,35 +445,25 @@ getting_started_add_documents_md: |-
459445
release_date: i64,
460446
genres: Vec<String>
461447
}
462-
impl Document for Movie {
463-
type UIDType = String;
464-
fn get_uid(&self) -> &Self::UIDType { &self.id }
465-
}
466448
```
467449
468450
You will often need this `Movie` struct in other parts of this documentation. (you will have to change it a bit sometimes)
469451
You can also use schemaless values, by putting a `serde_json::Value` inside your own struct like this:
470452
471453
```rust
472-
#[derive(Serialize, Deserialize, Debug)]
454+
#[derive(Serialize, Deserialize)]
473455
struct Movie {
474456
id: String,
475457
#[serde(flatten)]
476458
value: serde_json::Value,
477459
}
478-
479-
impl Document for Movie {
480-
type UIDType = String;
481-
fn get_uid(&self) -> &Self::UIDType { &self.id }
482-
}
483460
```
484461
485462
Then, add documents into the index:
486463
487464
```rust
488465
use meilisearch_sdk::{
489466
indexes::*,
490-
document::*,
491467
client::*,
492468
search::*,
493469
settings::*
@@ -582,10 +558,10 @@ getting_started_communicating_with_a_protected_instance: |-
582558
let client = Client::new("http://localhost:7700", "apiKey");
583559
client.index("movies").search()
584560
getting_started_add_meteorites: |-
585-
use serde::Deserialize;
561+
use serde::{Serialize, Deserialize};
586562
use std::fs::File;
587563
588-
#[derive(Serialize, Deserialize, Debug)]
564+
#[derive(Serialize, Deserialize)]
589565
struct Geo {
590566
lat: f64,
591567
lon: f64
@@ -601,11 +577,6 @@ getting_started_add_meteorites: |-
601577
_geo: Geo
602578
}
603579
604-
impl Document for Meteorite {
605-
type UIDType = String;
606-
fn get_uid(&self) -> &Self::UIDType { &self.id }
607-
}
608-
609580
let mut file = File::open("meteorites.json")?;
610581
let meteorites: Vec<Meteorite> = serde_json::from_reader(file)?;
611582
@@ -807,15 +778,11 @@ security_guide_delete_key_1: |-
807778
landing_getting_started_1: |-
808779
let client = Client::new("http://localhost:7700", "masterKey");
809780
810-
#[derive(Serialize, Deserialize, Debug)]
781+
#[derive(Serialize, Deserialize)]
811782
struct Movie {
812783
id: String,
813784
title: String
814785
}
815-
impl Document for Movie {
816-
type UIDType = String;
817-
fn get_uid(&self) -> &Self::UIDType { &self.id }
818-
}
819786
820787
client.index("movies").add_documents(&[
821788
Movie { "id": "1".to_string(), "title": "Carol".to_string() },

README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ NB: you can also download Meilisearch from **Homebrew** or **APT**.
8888
#### Add Documents <!-- omit in TOC -->
8989

9090
```rust
91-
use meilisearch_sdk::{document::*, client::*};
91+
use meilisearch_sdk::client::*;
9292
use serde::{Serialize, Deserialize};
9393
use futures::executor::block_on;
9494

@@ -99,14 +99,6 @@ struct Movie {
9999
genres: Vec<String>,
100100
}
101101

102-
// That trait is required to make a struct usable by an index
103-
impl Document for Movie {
104-
type UIDType = usize;
105-
106-
fn get_uid(&self) -> &Self::UIDType {
107-
&self.id
108-
}
109-
}
110102

111103
fn main() { block_on(async move {
112104
// Create a client (without sending any request so that can't fail)

examples/web_app/src/document.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use meilisearch_sdk::document::Document;
21
use serde::{Deserialize, Serialize};
32
use serde_json::{Map, Value};
43
use yew::prelude::*;
@@ -15,14 +14,6 @@ pub struct Crate {
1514
}
1615

1716
// Implement the Document trait so that we can use our struct with Meilisearch
18-
impl Document for Crate {
19-
type UIDType = String;
20-
21-
fn get_uid(&self) -> &Self::UIDType {
22-
&self.name
23-
}
24-
}
25-
2617
fn get_readable_download_count(this: &Map<String, Value>) -> String {
2718
if let Some(downloads) = this["downloads"].as_f64() {
2819
if downloads < 1000.0 {

src/client.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl Client {
176176
uid: impl AsRef<str>,
177177
primary_key: Option<&str>,
178178
) -> Result<Task, Error> {
179-
Ok(request::<Value, Task>(
179+
request::<Value, Task>(
180180
&format!("{}/indexes", self.host),
181181
&self.api_key,
182182
Method::Post(json!({
@@ -185,19 +185,19 @@ impl Client {
185185
})),
186186
202,
187187
)
188-
.await?)
188+
.await
189189
}
190190

191191
/// Delete an index from its UID.
192192
/// To delete an [Index], use the [Index::delete] method.
193193
pub async fn delete_index(&self, uid: impl AsRef<str>) -> Result<Task, Error> {
194-
Ok(request::<(), Task>(
194+
request::<(), Task>(
195195
&format!("{}/indexes/{}", self.host, uid.as_ref()),
196196
&self.api_key,
197197
Method::Delete,
198198
202,
199199
)
200-
.await?)
200+
.await
201201
}
202202

203203
/// Alias for [Client::list_all_indexes].
@@ -467,7 +467,7 @@ impl Client {
467467
/// # Example
468468
///
469469
/// ```
470-
/// # use meilisearch_sdk::{client::*, document, indexes::*, tasks::Task};
470+
/// # use meilisearch_sdk::{client::*, indexes::*, tasks::Task};
471471
/// # use serde::{Serialize, Deserialize};
472472
/// #
473473
/// # #[derive(Debug, Serialize, Deserialize, PartialEq)]
@@ -477,13 +477,6 @@ impl Client {
477477
/// # kind: String,
478478
/// # }
479479
/// #
480-
/// # impl document::Document for Document {
481-
/// # type UIDType = usize;
482-
/// #
483-
/// # fn get_uid(&self) -> &Self::UIDType {
484-
/// # &self.id
485-
/// # }
486-
/// # }
487480
/// #
488481
/// # futures::executor::block_on(async move {
489482
/// let client = Client::new("http://localhost:7700", "masterKey");

src/document.rs

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)