Skip to content

Commit b738b7e

Browse files
authored
Refactor README handling (#200)
* Refactor README.md, src/lib and README.tpl * Remove useless part in lib.rs
1 parent f941ae8 commit b738b7e

File tree

3 files changed

+59
-89
lines changed

3 files changed

+59
-89
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ println!("{:?}", movies.search().with_query("wonder").with_filter("id > 1 AND ge
178178
}
179179
```
180180

181-
### 🌐 Running in the Browser with WASM <!-- omit in TOC -->
181+
## 🌐 Running in the Browser with WASM <!-- omit in TOC -->
182182

183183
This crate fully supports WASM.
184184

README.tpl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,57 @@
4444

4545
See our [Documentation](https://docs.meilisearch.com/learn/tutorials/getting_started.html) or our [API References](https://docs.meilisearch.com/reference/api/).
4646

47+
## 🔧 Installation
48+
49+
To use `meilisearch-sdk`, add this to your `Cargo.toml`:
50+
51+
```toml
52+
[dependencies]
53+
meilisearch-sdk = "0.11.0"
54+
```
55+
56+
The following optional dependencies may also be useful:
57+
58+
```toml
59+
futures = "0.3" # To be able to block on async functions if you are not using an async runtime
60+
serde = { version = "1.0", features = ["derive"] }
61+
```
62+
63+
This crate is `async` but you can choose to use an async runtime like [tokio](https://crates.io/crates/tokio) or just [block on futures](https://docs.rs/futures/latest/futures/executor/fn.block_on.html).
64+
You can enable the `sync` feature to make most structs `Sync`. It may be a bit slower.
65+
66+
Using this crate is possible without [serde](https://crates.io/crates/serde), but a lot of features require serde.
67+
68+
### Run a MeiliSearch Instance <!-- omit in TOC -->
69+
70+
This crate requires a MeiliSearch server to run.
71+
72+
There are many easy ways to [download and run a MeiliSearch instance](https://docs.meilisearch.com/reference/features/installation.html#download-and-launch).
73+
74+
For example,using the `curl` command in [your Terminal](https://itconnect.uw.edu/learn/workshops/online-tutorials/web-publishing/what-is-a-terminal/):
75+
76+
```bash
77+
# Install MeiliSearch
78+
curl -L https://install.meilisearch.com | sh
79+
80+
# Launch MeiliSearch
81+
./meilisearch --master-key=masterKey
82+
```
83+
84+
NB: you can also download MeiliSearch from **Homebrew** or **APT**.
85+
4786
{{readme}}
4887

88+
## 🌐 Running in the Browser with WASM <!-- omit in TOC -->
89+
90+
This crate fully supports WASM.
91+
92+
The only difference between the WASM and the native version is that the native version has one more variant (`Error::Http`) in the Error enum. That should not matter so much but we could add this variant in WASM too.
93+
94+
However, making a program intended to run in a web browser requires a **very** different design than a CLI program. To see an example of a simple Rust web app using MeiliSearch, see the [our demo](./examples/web_app).
95+
96+
WARNING: `meilisearch-sdk` will panic if no Window is available (ex: Web extension).
97+
4998
## 🤖 Compatibility with MeiliSearch
5099

51100
This package only guarantees the compatibility with the [version v0.23.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.23.0).

src/lib.rs

Lines changed: 9 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,3 @@
1-
//! # 🔧 Installation
2-
//!
3-
//! To use `meilisearch-sdk`, add this to your `Cargo.toml`:
4-
//!
5-
//! ```toml
6-
//! [dependencies]
7-
//! meilisearch-sdk = "0.11.0"
8-
//! ```
9-
//!
10-
//! The following optional dependencies may also be useful:
11-
//!
12-
//! ```toml
13-
//! futures = "0.3" # To be able to block on async functions if you are not using an async runtime
14-
//! serde = { version = "1.0", features = ["derive"] }
15-
//! ```
16-
//!
17-
//! This crate is `async` but you can choose to use an async runtime like [tokio](https://crates.io/crates/tokio) or just [block on futures](https://docs.rs/futures/latest/futures/executor/fn.block_on.html).
18-
//! You can enable the `sync` feature to make most structs `Sync`. It may be a bit slower.
19-
//!
20-
//! Using this crate is possible without [serde](https://crates.io/crates/serde), but a lot of features require serde.
21-
//!
22-
//! ## Run a MeiliSearch Instance <!-- omit in TOC -->
23-
//!
24-
//! This crate requires a MeiliSearch server to run.
25-
//!
26-
//! There are many easy ways to [download and run a MeiliSearch instance](https://docs.meilisearch.com/reference/features/installation.html#download-and-launch).
27-
//!
28-
//! For example,using the `curl` command in [your Terminal](https://itconnect.uw.edu/learn/workshops/online-tutorials/web-publishing/what-is-a-terminal/):
29-
//!
30-
//! ```bash
31-
//! # Install MeiliSearch
32-
//! curl -L https://install.meilisearch.com | sh
33-
//!
34-
//! # Launch MeiliSearch
35-
//! ./meilisearch --master-key=masterKey
36-
//! ```
37-
//!
38-
//! NB: you can also download MeiliSearch from **Homebrew** or **APT**.
39-
//!
401
//! # 🚀 Getting Started
412
//!
423
//! ```rust
@@ -94,43 +55,17 @@
9455
//! index setting.
9556
//!
9657
//! ```
97-
//! # use meilisearch_sdk::{document::*, client::*, search::*};
58+
//! # use meilisearch_sdk::{client::*};
9859
//! # use serde::{Serialize, Deserialize};
9960
//! # use futures::executor::block_on;
100-
//! # #[derive(Serialize, Deserialize, Debug)]
101-
//! # struct Movie {
102-
//! # id: usize,
103-
//! # title: String,
104-
//! # genres: Vec<String>,
105-
//! # }
106-
//! # // That trait is required to make a struct usable by an index
107-
//! # impl Document for Movie {
108-
//! # type UIDType = usize;
109-
//! # fn get_uid(&self) -> &Self::UIDType {
110-
//! # &self.id
111-
//! # }
112-
//! # }
11361
//! # fn main() { block_on(async move {
114-
//! # // Create a client (without sending any request so that can't fail)
11562
//! # let client = Client::new("http://localhost:7700", "masterKey");
116-
//! # // Get the index called "movies"
11763
//! # let movies = client.get_or_create("movies").await.unwrap();
11864
//! let filterable_attributes = [
11965
//! "id",
12066
//! "genres"
12167
//! ];
12268
//! movies.set_filterable_attributes(&filterable_attributes).await.unwrap();
123-
//! # // Add some movies in the index
124-
//! # movies.add_documents(&[
125-
//! # Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()]},
126-
//! # Movie{id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()]},
127-
//! # Movie{id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure".to_string(), "Drama".to_string()]},
128-
//! # Movie{id: 4, title: String::from("Mad Max"), genres: vec!["Adventure".to_string(), "Science Fiction".to_string()]},
129-
//! # Movie{id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()]},
130-
//! # Movie{id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()]},
131-
//! # ], Some("id")).await.unwrap();
132-
//! # // Query movies (note that there is a typo)
133-
//! # println!("{:?}", movies.search().with_query("carol").execute::<Movie>().await.unwrap().hits);
13469
//! # })}
13570
//! ```
13671
//!
@@ -153,32 +88,28 @@
15388
//! # title: String,
15489
//! # genres: Vec<String>,
15590
//! # }
156-
//! # // That trait is required to make a struct usable by an index
15791
//! # impl Document for Movie {
15892
//! # type UIDType = usize;
15993
//! # fn get_uid(&self) -> &Self::UIDType {
16094
//! # &self.id
16195
//! # }
16296
//! # }
16397
//! # fn main() { block_on(async move {
164-
//! # // Create a client (without sending any request so that can't fail)
16598
//! # let client = Client::new("http://localhost:7700", "masterKey");
166-
//! # // Get the index called "movies"
16799
//! # let movies = client.get_or_create("movies").await.unwrap();
168100
//! # let filterable_attributes = [
169101
//! # "id",
170102
//! # "genres"
171103
//! # ];
172104
//! # movies.set_filterable_attributes(&filterable_attributes).await.unwrap();
173-
//! # // Add some movies in the index
174-
//! # movies.add_documents(&[
175-
//! # Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()]},
176-
//! # Movie{id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()]},
177-
//! # Movie{id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure".to_string(), "Drama".to_string()]},
178-
//! # Movie{id: 4, title: String::from("Mad Max"), genres: vec!["Adventure".to_string(), "Science Fiction".to_string()]},
179-
//! # Movie{id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()]},
180-
//! # Movie{id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()]},
181-
//! # ], Some("id")).await.unwrap();
105+
//! # movies.add_documents(&[
106+
//! # Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()]},
107+
//! # Movie{id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()]},
108+
//! # Movie{id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure".to_string(), "Drama".to_string()]},
109+
//! # Movie{id: 4, title: String::from("Mad Max"), genres: vec!["Adventure".to_string(), "Science Fiction".to_string()]},
110+
//! # Movie{id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()]},
111+
//! # Movie{id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()]},
112+
//! # ], Some("id")).await.unwrap();
182113
//! println!("{:?}", movies.search().with_query("wonder").with_filter("id > 1 AND genres = Action")
183114
//! .execute::<Movie>().await.unwrap().hits);
184115
//! # })}
@@ -200,16 +131,6 @@
200131
//! "query": "wonder"
201132
//! }
202133
//! ```
203-
//!
204-
//! ## 🌐 Running in the Browser with WASM <!-- omit in TOC -->
205-
//!
206-
//! This crate fully supports WASM.
207-
//!
208-
//! The only difference between the WASM and the native version is that the native version has one more variant (`Error::Http`) in the Error enum. That should not matter so much but we could add this variant in WASM too.
209-
//!
210-
//! However, making a program intended to run in a web browser requires a **very** different design than a CLI program. To see an example of a simple Rust web app using MeiliSearch, see the [our demo](./examples/web_app).
211-
//!
212-
//! WARNING: `meilisearch-sdk` will panic if no Window is available (ex: Web extension).
213134
214135
#![warn(clippy::all)]
215136
#![allow(clippy::needless_doctest_main)]

0 commit comments

Comments
 (0)