elastic_responses/
index.rs1use common::Shards;
6use parsing::{HttpResponseHead, IsOk, MaybeOkResponse, ResponseBody, Unbuffered};
7use error::*;
8
9#[derive(Deserialize, Debug)]
11pub struct IndexResponse {
12 #[serde(rename = "_index")] index: String,
13 #[serde(rename = "_type")] ty: String,
14 #[serde(rename = "_id")] id: String,
15 #[serde(rename = "_version")] version: Option<u32>,
16 created: bool,
17 #[serde(rename = "_shards")] shards: Shards,
18}
19
20impl IndexResponse {
21 pub fn shards(&self) -> &Shards {
23 &self.shards
24 }
25
26 pub fn created(&self) -> bool {
28 self.created
29 }
30
31 pub fn index(&self) -> &str {
33 &self.index
34 }
35
36 pub fn ty(&self) -> &str {
38 &self.ty
39 }
40
41 pub fn id(&self) -> &str {
43 &self.id
44 }
45
46 pub fn version(&self) -> Option<u32> {
48 self.version.clone()
49 }
50}
51
52impl IsOk for IndexResponse {
53 fn is_ok<B: ResponseBody>(head: HttpResponseHead, body: Unbuffered<B>) -> Result<MaybeOkResponse<B>, ParseResponseError> {
54 match head.status() {
55 200...299 => Ok(MaybeOkResponse::ok(body)),
56 _ => Ok(MaybeOkResponse::err(body)),
57 }
58 }
59}