Skip to content

Commit 97980d6

Browse files
bors[bot]ginglis13
andauthored
Merge #190
190: Add `get_raw_index` method r=curquiza a=ginglis13 ### Description Add get_raw_index to return `JsonIndex` object. Refactor `get_index` to first use `get_raw_index` before calling `into_index` on resulting `JsonIndex` object. Addresses #188 ### Testing Added doc test for new `get_raw_index` method and ran tests against meilisearch instance via `cargo test -- --test-threads=1` Co-authored-by: ginglis13 <[email protected]>
2 parents 82d1a80 + 54c0e7f commit 97980d6

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/client.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,35 @@ impl Client {
9898
/// # });
9999
/// ```
100100
pub async fn get_index(&self, uid: impl AsRef<str>) -> Result<Index, Error> {
101+
match self.get_raw_index(uid).await {
102+
Ok (raw_idx) => Ok(raw_idx.into_index(self)),
103+
Err(error) => Err(error),
104+
}
105+
}
106+
107+
/// Get a raw JSON [index](../indexes/struct.Index.html).
108+
///
109+
/// # Example
110+
///
111+
/// ```
112+
/// # use meilisearch_sdk::{client::*, indexes::*};
113+
///
114+
/// # futures::executor::block_on(async move {
115+
/// // create the client
116+
/// let client = Client::new("http://localhost:7700", "masterKey");
117+
/// # client.create_index("movies", None).await;
118+
///
119+
/// // get the index named "movies"
120+
/// let movies = client.get_raw_index("movies").await.unwrap();
121+
/// # });
122+
/// ```
123+
pub async fn get_raw_index(&self, uid: impl AsRef<str>) -> Result<JsonIndex, Error> {
101124
Ok(request::<(), JsonIndex>(
102125
&format!("{}/indexes/{}", self.host, uid.as_ref()),
103126
&self.api_key,
104127
Method::Get,
105128
200,
106-
).await?
107-
.into_index(self))
129+
).await?)
108130
}
109131

110132
/// Assume that an [index](../indexes/struct.Index.html) exist and create a corresponding object without any check.

0 commit comments

Comments
 (0)