Skip to content

Commit

Permalink
Replace manual Serialize impl of MultiSearchQuery with derive
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasKalbertodt committed Dec 12, 2024
1 parent 9f2e427 commit f4d5758
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
client::Client, errors::Error, indexes::Index, request::HttpClient, DefaultHttpClient,
};
use either::Either;
use serde::{de::DeserializeOwned, ser::SerializeStruct, Deserialize, Serialize, Serializer};
use serde::{de::DeserializeOwned, Deserialize, Serialize, Serializer};
use serde_json::{Map, Value};
use std::collections::HashMap;

Expand Down Expand Up @@ -591,26 +591,15 @@ impl<'a, Http: HttpClient> SearchQuery<'a, Http> {
}
}

// TODO: Make it works with the serde derive macro
// #[derive(Debug, Serialize, Clone)]
// #[serde(rename_all = "camelCase")]
#[derive(Debug, Clone)]
#[derive(Debug, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct MultiSearchQuery<'a, 'b, Http: HttpClient = DefaultHttpClient> {
// #[serde(skip_serializing)]
#[serde(skip_serializing)]
client: &'a Client<Http>,
#[serde(bound(serialize = ""))]
pub queries: Vec<SearchQuery<'b, Http>>,
}

impl<'a, 'b, Http: HttpClient> Serialize for MultiSearchQuery<'a, 'b, Http> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut strukt = serializer.serialize_struct("MultiSearchQuery", 1)?;
strukt.serialize_field("queries", &self.queries)?;
strukt.end()
}
}

#[allow(missing_docs)]
impl<'a, 'b, Http: HttpClient> MultiSearchQuery<'a, 'b, Http> {
Expand Down

0 comments on commit f4d5758

Please sign in to comment.