elastic_responses/
update.rs1use parsing::{HttpResponseHead, IsOk, MaybeOkResponse, ResponseBody, Unbuffered};
6use common::DocumentResult;
7use error::*;
8
9#[derive(Deserialize, Debug)]
11pub struct UpdateResponse {
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 #[serde(rename = "_routing")] routing: Option<String>,
17 result: DocumentResult,
18}
19
20impl UpdateResponse {
21 pub fn updated(&self) -> bool {
23 match self.result {
24 DocumentResult::Updated => true,
25 _ => false,
26 }
27 }
28
29 pub fn index(&self) -> &str {
31 &self.index
32 }
33
34 pub fn ty(&self) -> &str {
36 &self.ty
37 }
38
39 pub fn id(&self) -> &str {
41 &self.id
42 }
43
44 pub fn version(&self) -> Option<u32> {
46 self.version.clone()
47 }
48}
49
50impl IsOk for UpdateResponse {
51 fn is_ok<B: ResponseBody>(head: HttpResponseHead, body: Unbuffered<B>) -> Result<MaybeOkResponse<B>, ParseResponseError> {
52 match head.status() {
53 200...299 => Ok(MaybeOkResponse::ok(body)),
54 _ => Ok(MaybeOkResponse::err(body)),
55 }
56 }
57}