Skip to main content

qdrant_client/builders/
recommend_batch_points_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct RecommendBatchPointsBuilder {
6    /// Name of the collection
7    pub(crate) collection_name: Option<String>,
8    pub(crate) recommend_points: Option<Vec<RecommendPoints>>,
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 RecommendBatchPointsBuilder {
16    /// Name of the collection
17    pub fn collection_name(self, value: String) -> Self {
18        let mut new = self;
19        new.collection_name = Option::Some(value);
20        new
21    }
22    pub fn recommend_points(self, value: Vec<RecommendPoints>) -> Self {
23        let mut new = self;
24        new.recommend_points = Option::Some(value);
25        new
26    }
27    /// Options for specifying read consistency guarantees
28    pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
29        self,
30        value: VALUE,
31    ) -> Self {
32        let mut new = self;
33        new.read_consistency = Option::Some(value.into());
34        new
35    }
36    /// If set, overrides global timeout setting for this request. Unit is seconds.
37    pub fn timeout(self, value: u64) -> Self {
38        let mut new = self;
39        new.timeout = Option::Some(Option::Some(value));
40        new
41    }
42
43    fn build_inner(self) -> Result<RecommendBatchPoints, RecommendBatchPointsBuilderError> {
44        Ok(RecommendBatchPoints {
45            collection_name: match self.collection_name {
46                Some(value) => value,
47                None => {
48                    return Result::Err(core::convert::Into::into(
49                        ::derive_builder::UninitializedFieldError::from("collection_name"),
50                    ));
51                }
52            },
53            recommend_points: match self.recommend_points {
54                Some(value) => value,
55                None => {
56                    return Result::Err(core::convert::Into::into(
57                        ::derive_builder::UninitializedFieldError::from("recommend_points"),
58                    ));
59                }
60            },
61            read_consistency: { convert_option(&self.read_consistency) },
62            timeout: self.timeout.unwrap_or_default(),
63        })
64    }
65    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
66    fn create_empty() -> Self {
67        Self {
68            collection_name: core::default::Default::default(),
69            recommend_points: core::default::Default::default(),
70            read_consistency: core::default::Default::default(),
71            timeout: core::default::Default::default(),
72        }
73    }
74}
75
76impl From<RecommendBatchPointsBuilder> for RecommendBatchPoints {
77    fn from(value: RecommendBatchPointsBuilder) -> Self {
78        value.build_inner().unwrap_or_else(|_| {
79            panic!(
80                "Failed to convert {0} to {1}",
81                "RecommendBatchPointsBuilder", "RecommendBatchPoints"
82            )
83        })
84    }
85}
86
87impl RecommendBatchPointsBuilder {
88    /// Builds the desired type. Can often be omitted.
89    pub fn build(self) -> RecommendBatchPoints {
90        self.build_inner().unwrap_or_else(|_| {
91            panic!(
92                "Failed to build {0} into {1}",
93                "RecommendBatchPointsBuilder", "RecommendBatchPoints"
94            )
95        })
96    }
97}
98
99impl RecommendBatchPointsBuilder {
100    pub(crate) fn empty() -> Self {
101        Self::create_empty()
102    }
103}
104
105/// Error type for RecommendBatchPointsBuilder
106#[non_exhaustive]
107#[derive(Debug)]
108pub enum RecommendBatchPointsBuilderError {
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 RecommendBatchPointsBuilderError {
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 RecommendBatchPointsBuilderError {}
129
130// Implementing From trait for conversion from UninitializedFieldError
131impl From<derive_builder::UninitializedFieldError> for RecommendBatchPointsBuilderError {
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 RecommendBatchPointsBuilderError {
139    fn from(error: String) -> Self {
140        Self::ValidationError(error)
141    }
142}