Skip to main content

qdrant_client/builders/
discover_batch_points_builder.rs

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