Skip to content

Commit 59130d0

Browse files
authored
Replace Vec references with slices (#22)
1 parent c906316 commit 59130d0

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async fn main() {
5757
let mut books = client.get_or_create("books").await.unwrap();
5858

5959
// Add some books in the index
60-
books.add_documents(&vec![
60+
books.add_documents(&[
6161
Book{book_id: 123, title: String::from("Pride and Prejudice")},
6262
Book{book_id: 456, title: String::from("Le Petit Prince")},
6363
Book{book_id: 1, title: String::from("Alice In Wonderland")},

src/indexes.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'a> Index<'a> {
111111
/// let mut movies = client.get_or_create("movies").await.unwrap();
112112
///
113113
/// // add some documents
114-
/// # movies.add_or_replace(&vec![Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name")).await.unwrap();
114+
/// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name")).await.unwrap();
115115
/// # std::thread::sleep(std::time::Duration::from_secs(1));
116116
///
117117
/// let query = Query::new("Interstellar").with_limit(5);
@@ -167,7 +167,7 @@ impl<'a> Index<'a> {
167167
/// # client.create_index("movies", None).await;
168168
/// let movies = client.get_index("movies").await.unwrap();
169169
/// # let mut movies = client.get_index("movies").await.unwrap();
170-
/// # movies.add_or_replace(&vec![Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap();
170+
/// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap();
171171
/// # std::thread::sleep(std::time::Duration::from_secs(1));
172172
/// #
173173
/// // retrieve a document (you have to put the document in the index before)
@@ -227,7 +227,7 @@ impl<'a> Index<'a> {
227227
/// let movie_index = client.get_index("movies").await.unwrap();
228228
/// # let mut movie_index = client.get_index("movies").await.unwrap();
229229
///
230-
/// # movie_index.add_or_replace(&vec![Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap();
230+
/// # movie_index.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap();
231231
/// # std::thread::sleep(std::time::Duration::from_secs(1));
232232
/// #
233233
/// // retrieve movies (you have to put some movies in the index before)
@@ -300,7 +300,7 @@ impl<'a> Index<'a> {
300300
/// let client = Client::new("http://localhost:7700", "");
301301
/// let mut movie_index = client.get_or_create("movies").await.unwrap();
302302
///
303-
/// movie_index.add_or_replace(&vec![
303+
/// movie_index.add_or_replace(&[
304304
/// Movie{
305305
/// name: String::from("Interstellar"),
306306
/// description: String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")
@@ -324,7 +324,7 @@ impl<'a> Index<'a> {
324324
/// ```
325325
pub async fn add_or_replace<T: Document>(
326326
&'a self,
327-
documents: &Vec<T>,
327+
documents: &[T],
328328
primary_key: Option<&str>,
329329
) -> Result<Progress<'a>, Error> {
330330
let url = if let Some(primary_key) = primary_key {
@@ -336,7 +336,7 @@ impl<'a> Index<'a> {
336336
format!("{}/indexes/{}/documents", self.client.host, self.uid)
337337
};
338338
Ok(
339-
request::<&Vec<T>, ProgressJson>(
339+
request::<&[T], ProgressJson>(
340340
&url,
341341
self.client.apikey,
342342
Method::Post(documents),
@@ -349,7 +349,7 @@ impl<'a> Index<'a> {
349349
/// Alias for [add_or_replace](#method.add_or_replace).
350350
pub async fn add_documents<T: Document>(
351351
&'a self,
352-
documents: &Vec<T>,
352+
documents: &[T],
353353
primary_key: Option<&str>,
354354
) -> Result<Progress<'a>, Error> {
355355
self.add_or_replace(documents, primary_key).await
@@ -388,7 +388,7 @@ impl<'a> Index<'a> {
388388
/// let client = Client::new("http://localhost:7700", "");
389389
/// let mut movie_index = client.get_or_create("movies").await.unwrap();
390390
///
391-
/// movie_index.add_or_update(&vec![
391+
/// movie_index.add_or_update(&[
392392
/// Movie{
393393
/// name: String::from("Interstellar"),
394394
/// description: String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")
@@ -412,7 +412,7 @@ impl<'a> Index<'a> {
412412
/// ```
413413
pub async fn add_or_update<T: Document>(
414414
&'a self,
415-
documents: &Vec<T>,
415+
documents: &[T],
416416
primary_key: Option<&str>,
417417
) -> Result<Progress<'a>, Error> {
418418
let url = if let Some(primary_key) = primary_key {
@@ -424,7 +424,7 @@ impl<'a> Index<'a> {
424424
format!("{}/indexes/{}/documents", self.client.host, self.uid)
425425
};
426426
Ok(
427-
request::<&Vec<T>, ProgressJson>(&url, self.client.apikey, Method::Put(documents), 202).await?
427+
request::<&[T], ProgressJson>(&url, self.client.apikey, Method::Put(documents), 202).await?
428428
.into_progress(self),
429429
)
430430
}
@@ -502,7 +502,7 @@ impl<'a> Index<'a> {
502502
/// let client = Client::new("http://localhost:7700", "");
503503
/// let mut movies = client.get_or_create("movies").await.unwrap();
504504
///
505-
/// # movies.add_or_replace(&vec![Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap();
505+
/// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap();
506506
/// # std::thread::sleep(std::time::Duration::from_secs(1));
507507
/// // add a document with id = Interstellar
508508
///
@@ -551,18 +551,18 @@ impl<'a> Index<'a> {
551551
/// let mut movies = client.get_or_create("movies").await.unwrap();
552552
///
553553
/// // add some documents
554-
/// # movies.add_or_replace(&vec![Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name")).await.unwrap();
554+
/// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name")).await.unwrap();
555555
/// # std::thread::sleep(std::time::Duration::from_secs(1));
556556
///
557557
/// // delete some documents
558-
/// movies.delete_documents(&vec!["Interstellar", "Unknown"]).await.unwrap();
558+
/// movies.delete_documents(&["Interstellar", "Unknown"]).await.unwrap();
559559
/// # }
560560
/// ```
561561
pub async fn delete_documents<T: Display + Serialize + std::fmt::Debug>(
562562
&'a self,
563-
uids: &Vec<T>,
563+
uids: &[T],
564564
) -> Result<Progress<'a>, Error> {
565-
Ok(request::<&Vec<T>, ProgressJson>(
565+
Ok(request::<&[T], ProgressJson>(
566566
&format!(
567567
"{}/indexes/{}/documents/delete-batch",
568568
self.client.host, self.uid

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
//! let mut books = client.get_or_create("books").await.unwrap();
5353
//!
5454
//! // Add some books in the index
55-
//! books.add_documents(&vec![
55+
//! books.add_documents(&[
5656
//! Book{book_id: 123, title: String::from("Pride and Prejudice")},
5757
//! Book{book_id: 456, title: String::from("Le Petit Prince")},
5858
//! Book{book_id: 1, title: String::from("Alice In Wonderland")},

0 commit comments

Comments
 (0)