Skip to main content

qdrant_client/builders/
delete_payload_points_builder.rs

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