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