Skip to main content

qdrant_client/builders/
recommend_batch_points_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[must_use]
5#[derive(Clone)]
6pub struct RecommendBatchPointsBuilder {
7    /// Name of the collection
8    pub(crate) collection_name: Option<String>,
9    pub(crate) recommend_points: Option<Vec<RecommendPoints>>,
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 RecommendBatchPointsBuilder {
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 recommend_points(self, value: Vec<RecommendPoints>) -> Self {
24        let mut new = self;
25        new.recommend_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<RecommendBatchPoints, RecommendBatchPointsBuilderError> {
45        Ok(RecommendBatchPoints {
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            recommend_points: match self.recommend_points {
55                Some(value) => value,
56                None => {
57                    return Result::Err(core::convert::Into::into(
58                        ::derive_builder::UninitializedFieldError::from("recommend_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            recommend_points: core::default::Default::default(),
71            read_consistency: core::default::Default::default(),
72            timeout: core::default::Default::default(),
73        }
74    }
75}
76
77impl From<RecommendBatchPointsBuilder> for RecommendBatchPoints {
78    fn from(value: RecommendBatchPointsBuilder) -> Self {
79        value.build_inner().unwrap_or_else(|_| {
80            panic!(
81                "Failed to convert {0} to {1}",
82                "RecommendBatchPointsBuilder", "RecommendBatchPoints"
83            )
84        })
85    }
86}
87
88impl RecommendBatchPointsBuilder {
89    /// Builds the desired type. Can often be omitted.
90    pub fn build(self) -> RecommendBatchPoints {
91        self.build_inner().unwrap_or_else(|_| {
92            panic!(
93                "Failed to build {0} into {1}",
94                "RecommendBatchPointsBuilder", "RecommendBatchPoints"
95            )
96        })
97    }
98}
99
100impl RecommendBatchPointsBuilder {
101    pub(crate) fn empty() -> Self {
102        Self::create_empty()
103    }
104}
105
106/// Error type for RecommendBatchPointsBuilder
107#[non_exhaustive]
108#[derive(Debug)]
109pub enum RecommendBatchPointsBuilderError {
110    /// Uninitialized field
111    UninitializedField(&'static str),
112    /// Custom validation error
113    ValidationError(String),
114}
115
116// Implementing the Display trait for better error messages
117impl std::fmt::Display for RecommendBatchPointsBuilderError {
118    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
119        match self {
120            Self::UninitializedField(field) => {
121                write!(f, "`{field}` must be initialized")
122            }
123            Self::ValidationError(error) => write!(f, "{error}"),
124        }
125    }
126}
127
128// Implementing the Error trait
129impl std::error::Error for RecommendBatchPointsBuilderError {}
130
131// Implementing From trait for conversion from UninitializedFieldError
132impl From<derive_builder::UninitializedFieldError> for RecommendBatchPointsBuilderError {
133    fn from(error: derive_builder::UninitializedFieldError) -> Self {
134        Self::UninitializedField(error.field_name())
135    }
136}
137
138// Implementing From trait for conversion from String
139impl From<String> for RecommendBatchPointsBuilderError {
140    fn from(error: String) -> Self {
141        Self::ValidationError(error)
142    }
143}