Skip to content

Commit 9c6ded1

Browse files
authored
Rust fmt on the code base (#216)
1 parent 75f9420 commit 9c6ded1

File tree

11 files changed

+419
-259
lines changed

11 files changed

+419
-259
lines changed

examples/web_app/src/document.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ impl Document for Crate {
2323
}
2424
}
2525

26-
2726
fn get_readable_download_count(this: &Map<String, Value>) -> String {
2827
if let Some(downloads) = this["downloads"].as_f64() {
2928
if downloads < 1000.0 {
@@ -39,7 +38,10 @@ fn get_readable_download_count(this: &Map<String, Value>) -> String {
3938
}
4039

4140
pub fn display(this: &Map<String, Value>) -> Html {
42-
let mut url = format!("https://lib.rs/crates/{}", this["name"].as_str().unwrap_or_default());
41+
let mut url = format!(
42+
"https://lib.rs/crates/{}",
43+
this["name"].as_str().unwrap_or_default()
44+
);
4345
url = url.replace("<em>", "");
4446
url = url.replace("</em>", "");
4547

examples/web_app/src/lib.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![recursion_limit = "512"]
2+
use lazy_static::lazy_static;
23
use meilisearch_sdk::{
34
client::Client,
45
indexes::Index,
@@ -9,10 +10,9 @@ use std::rc::Rc;
910
use wasm_bindgen::prelude::*;
1011
use wasm_bindgen_futures::spawn_local;
1112
use yew::prelude::*;
12-
use lazy_static::lazy_static;
1313

1414
mod document;
15-
use crate::document::{Crate, display};
15+
use crate::document::{display, Crate};
1616

1717
lazy_static! {
1818
static ref CLIENT: Client = Client::new(
@@ -36,7 +36,11 @@ enum Msg {
3636
/// An event sent to update the results with a query
3737
Input(String),
3838
/// The event sent to display new results once they are received
39-
Update{results: Vec<Map<String, Value>>, processing_time_ms: usize, request_id: usize},
39+
Update {
40+
results: Vec<Map<String, Value>>,
41+
processing_time_ms: usize,
42+
request_id: usize,
43+
},
4044
}
4145

4246
impl Component for Model {
@@ -87,17 +91,21 @@ impl Component for Model {
8791
}
8892

8993
// We send a new event with the up-to-date data so that we can update the results and display them.
90-
link.send_message(Msg::Update{
94+
link.send_message(Msg::Update {
9195
results: fresh_formatted_results,
9296
processing_time_ms: fresh_results.processing_time_ms,
93-
request_id
97+
request_id,
9498
});
9599
});
96100
false
97101
}
98102

99103
// Sent when new results are received
100-
Msg::Update{results, processing_time_ms, request_id} => {
104+
Msg::Update {
105+
results,
106+
processing_time_ms,
107+
request_id,
108+
} => {
101109
if request_id >= self.latest_sent_request_id {
102110
self.results = results;
103111
self.processing_time_ms = processing_time_ms;

src/client.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{errors::*, indexes::*, request::*, Rc};
2+
use serde::Deserialize;
23
use serde_json::{json, Value};
3-
use serde::{Deserialize};
44
use std::collections::HashMap;
55

66
/// The top-level struct of the SDK, representing a client containing [indexes](../indexes/struct.Index.html).
@@ -25,7 +25,7 @@ impl Client {
2525
pub fn new(host: impl Into<String>, api_key: impl Into<String>) -> Client {
2626
Client {
2727
host: Rc::new(host.into()),
28-
api_key: Rc::new(api_key.into())
28+
api_key: Rc::new(api_key.into()),
2929
}
3030
}
3131

@@ -44,8 +44,8 @@ impl Client {
4444
/// # });
4545
/// ```
4646
pub async fn list_all_indexes(&self) -> Result<Vec<Index>, Error> {
47-
match self.list_all_indexes_raw().await{
48-
Ok (json_indexes) => Ok({
47+
match self.list_all_indexes_raw().await {
48+
Ok(json_indexes) => Ok({
4949
let mut indexes = Vec::new();
5050
for json_index in json_indexes {
5151
indexes.push(json_index.into_index(self))
@@ -76,7 +76,8 @@ impl Client {
7676
&self.api_key,
7777
Method::Get,
7878
200,
79-
).await?;
79+
)
80+
.await?;
8081

8182
Ok(json_indexes)
8283
}
@@ -99,7 +100,7 @@ impl Client {
99100
/// ```
100101
pub async fn get_index(&self, uid: impl AsRef<str>) -> Result<Index, Error> {
101102
match self.get_raw_index(uid).await {
102-
Ok (raw_idx) => Ok(raw_idx.into_index(self)),
103+
Ok(raw_idx) => Ok(raw_idx.into_index(self)),
103104
Err(error) => Err(error),
104105
}
105106
}
@@ -130,7 +131,7 @@ impl Client {
130131
Index {
131132
uid: Rc::new(uid.into()),
132133
host: Rc::clone(&self.host),
133-
api_key: Rc::clone(&self.api_key)
134+
api_key: Rc::clone(&self.api_key),
134135
}
135136
}
136137

@@ -165,16 +166,17 @@ impl Client {
165166
"primaryKey": primary_key,
166167
})),
167168
201,
168-
).await?
169+
)
170+
.await?
169171
.into_index(self))
170172
}
171173

172174
/// Delete an index from its UID if it exists.
173175
/// To delete an index if it exists from the [`Index`] object, use the [Index::delete_if_exists] method.
174176
pub async fn delete_index_if_exists(&self, uid: &str) -> Result<bool, Error> {
175177
match self.delete_index(uid).await {
176-
Ok (_) => Ok(true),
177-
Err (Error::MeiliSearchError {
178+
Ok(_) => Ok(true),
179+
Err(Error::MeiliSearchError {
178180
error_message: _,
179181
error_code: ErrorCode::IndexNotFound,
180182
error_type: _,
@@ -192,7 +194,8 @@ impl Client {
192194
&self.api_key,
193195
Method::Delete,
194196
204,
195-
).await?)
197+
)
198+
.await?)
196199
}
197200

198201
/// This will try to get an index and create the index if it does not exist.
@@ -232,7 +235,8 @@ impl Client {
232235
&self.api_key,
233236
Method::Get,
234237
200,
235-
).await
238+
)
239+
.await
236240
}
237241

238242
/// Get health of MeiliSearch server.
@@ -296,7 +300,8 @@ impl Client {
296300
&self.api_key,
297301
Method::Get,
298302
200,
299-
).await
303+
)
304+
.await
300305
}
301306

302307
/// Get version of the MeiliSearch server.
@@ -317,7 +322,8 @@ impl Client {
317322
&self.api_key,
318323
Method::Get,
319324
200,
320-
).await
325+
)
326+
.await
321327
}
322328
}
323329

@@ -373,7 +379,7 @@ pub struct Version {
373379

374380
#[cfg(test)]
375381
mod tests {
376-
use crate::{client::*};
382+
use crate::client::*;
377383
use futures_await_test::async_test;
378384

379385
#[async_test]
@@ -462,7 +468,10 @@ mod tests {
462468
async fn test_get_primary_key() {
463469
let client = Client::new("http://localhost:7700", "masterKey");
464470
let index_name = "get_primary_key";
465-
client.create_index(index_name, Some("primary_key")).await.unwrap();
471+
client
472+
.create_index(index_name, Some("primary_key"))
473+
.await
474+
.unwrap();
466475
let primary_key = client.index(index_name).get_primary_key().await;
467476
assert!(primary_key.is_ok());
468477
assert_eq!(primary_key.unwrap().unwrap(), "primary_key");

src/dumps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct DumpInfo {
6161
pub error: Option<serde_json::Value>,
6262
pub started_at: Option<String>,
6363
#[serde(skip_serializing_if = "Option::is_none")]
64-
pub finished_at: Option<String>
64+
pub finished_at: Option<String>,
6565
}
6666

6767
/// Dump related methods.\

src/errors.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ pub enum ErrorCode {
9494
Unknown(UnknownErrorCode),
9595
}
9696

97-
9897
#[derive(Clone)]
9998
pub struct UnknownErrorCode(String);
10099

@@ -258,7 +257,6 @@ impl std::error::Error for Error {}
258257

259258
impl From<&serde_json::Value> for Error {
260259
fn from(json: &serde_json::Value) -> Error {
261-
262260
let error_message = json
263261
.get("message")
264262
.and_then(|v| v.as_str())

0 commit comments

Comments
 (0)