qdrant_client/builders/
update_point_vectors_builder.rs

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