Skip to main content

qdrant_client/builders/
search_batch_points_builder.rs

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