Skip to main content

qdrant_client/builders/
update_batch_points_builder.rs

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