qdrant_client/builders/
search_batch_points_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct SearchBatchPointsBuilder {
6    /// Name of the collection
7    pub(crate) collection_name: Option<String>,
8    pub(crate) search_points: Option<Vec<SearchPoints>>,
9    /// Options for specifying read consistency guarantees
10    read_consistency: Option<read_consistency::Value>,
11    /// If set, overrides global timeout setting for this request. Unit is seconds.
12    pub(crate) timeout: Option<Option<u64>>,
13}
14
15impl SearchBatchPointsBuilder {
16    /// Name of the collection
17    #[allow(unused_mut)]
18    pub fn collection_name(self, value: String) -> Self {
19        let mut new = self;
20        new.collection_name = Option::Some(value);
21        new
22    }
23    #[allow(unused_mut)]
24    pub fn search_points(self, value: Vec<SearchPoints>) -> Self {
25        let mut new = self;
26        new.search_points = Option::Some(value);
27        new
28    }
29    /// Options for specifying read consistency guarantees
30    #[allow(unused_mut)]
31    pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
32        self,
33        value: VALUE,
34    ) -> Self {
35        let mut new = self;
36        new.read_consistency = Option::Some(value.into());
37        new
38    }
39    /// If set, overrides global timeout setting for this request. Unit is seconds.
40    #[allow(unused_mut)]
41    pub fn timeout(self, value: u64) -> Self {
42        let mut new = self;
43        new.timeout = Option::Some(Option::Some(value));
44        new
45    }
46
47    fn build_inner(self) -> Result<SearchBatchPoints, SearchBatchPointsBuilderError> {
48        Ok(SearchBatchPoints {
49            collection_name: match self.collection_name {
50                Some(value) => value,
51                None => {
52                    return Result::Err(core::convert::Into::into(
53                        ::derive_builder::UninitializedFieldError::from("collection_name"),
54                    ));
55                }
56            },
57            search_points: match self.search_points {
58                Some(value) => value,
59                None => {
60                    return Result::Err(core::convert::Into::into(
61                        ::derive_builder::UninitializedFieldError::from("search_points"),
62                    ));
63                }
64            },
65            read_consistency: { convert_option(&self.read_consistency) },
66            timeout: self.timeout.unwrap_or_default(),
67        })
68    }
69    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
70    fn create_empty() -> Self {
71        Self {
72            collection_name: core::default::Default::default(),
73            search_points: core::default::Default::default(),
74            read_consistency: core::default::Default::default(),
75            timeout: core::default::Default::default(),
76        }
77    }
78}
79
80impl From<SearchBatchPointsBuilder> for SearchBatchPoints {
81    fn from(value: SearchBatchPointsBuilder) -> Self {
82        value.build_inner().unwrap_or_else(|_| {
83            panic!(
84                "Failed to convert {0} to {1}",
85                "SearchBatchPointsBuilder", "SearchBatchPoints"
86            )
87        })
88    }
89}
90
91impl SearchBatchPointsBuilder {
92    /// Builds the desired type. Can often be omitted.
93    pub fn build(self) -> SearchBatchPoints {
94        self.build_inner().unwrap_or_else(|_| {
95            panic!(
96                "Failed to build {0} into {1}",
97                "SearchBatchPointsBuilder", "SearchBatchPoints"
98            )
99        })
100    }
101}
102
103impl SearchBatchPointsBuilder {
104    pub(crate) fn empty() -> Self {
105        Self::create_empty()
106    }
107}
108
109#[non_exhaustive]
110#[derive(Debug)]
111pub enum SearchBatchPointsBuilderError {
112    /// Uninitialized field
113    UninitializedField(&'static str),
114    /// Custom validation error
115    ValidationError(String),
116}
117
118// Implementing the Display trait for better error messages
119impl std::fmt::Display for SearchBatchPointsBuilderError {
120    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
121        match self {
122            Self::UninitializedField(field) => {
123                write!(f, "`{field}` must be initialized")
124            }
125            Self::ValidationError(error) => write!(f, "{error}"),
126        }
127    }
128}
129
130// Implementing the Error trait
131impl std::error::Error for SearchBatchPointsBuilderError {}
132
133// Implementing From trait for conversion from UninitializedFieldError
134impl From<derive_builder::UninitializedFieldError> for SearchBatchPointsBuilderError {
135    fn from(error: derive_builder::UninitializedFieldError) -> Self {
136        Self::UninitializedField(error.field_name())
137    }
138}
139
140// Implementing From trait for conversion from String
141impl From<String> for SearchBatchPointsBuilderError {
142    fn from(error: String) -> Self {
143        Self::ValidationError(error)
144    }
145}