Skip to main content

qdrant_client/builders/
discover_batch_points_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct DiscoverBatchPointsBuilder {
6    /// Name of the collection
7    pub(crate) collection_name: Option<String>,
8    pub(crate) discover_points: Option<Vec<DiscoverPoints>>,
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 DiscoverBatchPointsBuilder {
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 discover_points(self, value: Vec<DiscoverPoints>) -> Self {
23        let mut new = self;
24        new.discover_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<DiscoverBatchPoints, DiscoverBatchPointsBuilderError> {
44        Ok(DiscoverBatchPoints {
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            discover_points: match self.discover_points {
54                Some(value) => value,
55                None => {
56                    return Result::Err(core::convert::Into::into(
57                        ::derive_builder::UninitializedFieldError::from("discover_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            discover_points: core::default::Default::default(),
70            read_consistency: core::default::Default::default(),
71            timeout: core::default::Default::default(),
72        }
73    }
74}
75
76impl From<DiscoverBatchPointsBuilder> for DiscoverBatchPoints {
77    fn from(value: DiscoverBatchPointsBuilder) -> Self {
78        value.build_inner().unwrap_or_else(|_| {
79            panic!(
80                "Failed to convert {0} to {1}",
81                "DiscoverBatchPointsBuilder", "DiscoverBatchPoints"
82            )
83        })
84    }
85}
86
87impl DiscoverBatchPointsBuilder {
88    /// Builds the desired type. Can often be omitted.
89    pub fn build(self) -> DiscoverBatchPoints {
90        self.build_inner().unwrap_or_else(|_| {
91            panic!(
92                "Failed to build {0} into {1}",
93                "DiscoverBatchPointsBuilder", "DiscoverBatchPoints"
94            )
95        })
96    }
97}
98
99impl DiscoverBatchPointsBuilder {
100    pub(crate) fn empty() -> Self {
101        Self::create_empty()
102    }
103}
104
105// src/builders/discover_batch_points_builder.rs
106
107#[non_exhaustive]
108#[derive(Debug)]
109pub enum DiscoverBatchPointsBuilderError {
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 DiscoverBatchPointsBuilderError {
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 DiscoverBatchPointsBuilderError {}
130
131// Implementing From trait for conversion from UninitializedFieldError
132impl From<derive_builder::UninitializedFieldError> for DiscoverBatchPointsBuilderError {
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 DiscoverBatchPointsBuilderError {
140    fn from(error: String) -> Self {
141        Self::ValidationError(error)
142    }
143}