Skip to content

Commit e14ef71

Browse files
committed
Update lib.rs
1 parent 9baa6a9 commit e14ef71

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

src/lib.rs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,47 +41,48 @@
4141
//! use futures::executor::block_on;
4242
//!
4343
//! #[derive(Serialize, Deserialize, Debug)]
44-
//! struct Book {
45-
//! book_id: usize,
44+
//! struct Movie {
45+
//! id: usize,
4646
//! title: String,
47+
//! genres: Vec<String>,
4748
//! }
4849
//!
4950
//! // That trait is required to make a struct usable by an index
50-
//! impl Document for Book {
51+
//! impl Document for Movie {
5152
//! type UIDType = usize;
5253
//!
5354
//! fn get_uid(&self) -> &Self::UIDType {
54-
//! &self.book_id
55+
//! &self.id
5556
//! }
5657
//! }
5758
//!
58-
//! fn main() { block_on(async move {
59-
//! // Create a client (without sending any request so that can't fail)
60-
//! let client = Client::new("http://localhost:7700", "masterKey");
61-
//!
62-
//! // Get the index called "books"
63-
//! let books = client.get_or_create("books").await.unwrap();
64-
//!
65-
//! // Add some books in the index
66-
//! books.add_documents(&[
67-
//! Book{book_id: 123, title: String::from("Pride and Prejudice")},
68-
//! Book{book_id: 456, title: String::from("Le Petit Prince")},
69-
//! Book{book_id: 1, title: String::from("Alice In Wonderland")},
70-
//! Book{book_id: 1344, title: String::from("The Hobbit")},
71-
//! Book{book_id: 4, title: String::from("Harry Potter and the Half-Blood Prince")},
72-
//! Book{book_id: 42, title: String::from("The Hitchhiker's Guide to the Galaxy")},
73-
//! ], Some("book_id")).await.unwrap();
74-
//!
75-
//! // Query books (note that there is a typo)
76-
//! println!("{:?}", books.search().with_query("harry pottre").execute::<Book>().await.unwrap().hits);
77-
//! })}
78-
//! ```
79-
//!
80-
//! Output:
81-
//!
82-
//! ```text
83-
//! [Book { book_id: 4, title: "Harry Potter and the Half-Blood Prince" }]
84-
//! ```
59+
// !fn main() { block_on(async move {
60+
// ! // Create a client (without sending any request so that can't fail)
61+
// ! let client = Client::new("http://localhost:7700", "masterKey");
62+
// !
63+
// ! // Get the index called "movies"
64+
// ! let movies = client.get_or_create("movies").await.unwrap();
65+
// !
66+
// ! // Add some movies in the index
67+
// ! movies.add_documents(&[
68+
// ! Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance", "Drama"]},
69+
// ! Movie{id: 2, title: String::from("Wonder Woman"), genres: vec!["Action", "Adventure"]},
70+
// ! Movie{id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure", "Drama"]},
71+
// ! Movie{id: 4, title: String::from("Mad Max"), genres: vec!["Adventure", "Science Fiction"]},
72+
// ! Movie{id: 5, title: String::from("Moana"), genres: vec!["Fantasy", "Action"]},
73+
// ! Movie{id: 6, title: String::from("Philadelphia"), genres: vec!["Drama"]},
74+
// ! ], Some("id")).await.unwrap();
75+
// !
76+
// ! // Query movies (note that there is a typo)
77+
// ! println!("{:?}", movies.search().with_query("Carol").execute::<Movie>().await.unwrap().hits);
78+
// !})}
79+
// !```
80+
// !
81+
// !Output:
82+
// !
83+
// !```
84+
// ![Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance", "Drama"]}]
85+
// !```
8586
//!
8687
//! ## 🌐 Running in the Browser with WASM <!-- omit in TOC -->
8788
//!

0 commit comments

Comments
 (0)