Skip to main content

qdrant_client/builders/
delete_point_vectors_builder.rs

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