Skip to main content

qdrant_client/builders/
delete_payload_points_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct DeletePayloadPointsBuilder {
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    /// List of keys to delete
11    pub(crate) keys: Option<Vec<String>>,
12    /// Affected points
13    points_selector: Option<points_selector::PointsSelectorOneOf>,
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 DeletePayloadPointsBuilder {
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    /// List of keys to delete
36    pub fn keys(self, value: Vec<String>) -> Self {
37        let mut new = self;
38        new.keys = Option::Some(value);
39        new
40    }
41    /// Affected points
42    pub fn points_selector<VALUE: core::convert::Into<points_selector::PointsSelectorOneOf>>(
43        self,
44        value: VALUE,
45    ) -> Self {
46        let mut new = self;
47        new.points_selector = 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<DeletePayloadPoints, DeletePayloadPointsBuilderError> {
73        Ok(DeletePayloadPoints {
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            keys: match self.keys {
84                Some(value) => value,
85                None => {
86                    return Result::Err(core::convert::Into::into(
87                        ::derive_builder::UninitializedFieldError::from("keys"),
88                    ));
89                }
90            },
91            points_selector: { convert_option(&self.points_selector) },
92            ordering: self.ordering.unwrap_or_default(),
93            shard_key_selector: self.shard_key_selector.unwrap_or_default(),
94            timeout: self.timeout.unwrap_or_default(),
95        })
96    }
97    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
98    fn create_empty() -> Self {
99        Self {
100            collection_name: core::default::Default::default(),
101            wait: core::default::Default::default(),
102            keys: core::default::Default::default(),
103            points_selector: core::default::Default::default(),
104            ordering: core::default::Default::default(),
105            shard_key_selector: core::default::Default::default(),
106            timeout: core::default::Default::default(),
107        }
108    }
109}
110
111impl From<DeletePayloadPointsBuilder> for DeletePayloadPoints {
112    fn from(value: DeletePayloadPointsBuilder) -> Self {
113        value.build_inner().unwrap_or_else(|_| {
114            panic!(
115                "Failed to convert {0} to {1}",
116                "DeletePayloadPointsBuilder", "DeletePayloadPoints"
117            )
118        })
119    }
120}
121
122impl DeletePayloadPointsBuilder {
123    /// Builds the desired type. Can often be omitted.
124    pub fn build(self) -> DeletePayloadPoints {
125        self.build_inner().unwrap_or_else(|_| {
126            panic!(
127                "Failed to build {0} into {1}",
128                "DeletePayloadPointsBuilder", "DeletePayloadPoints"
129            )
130        })
131    }
132}
133
134impl DeletePayloadPointsBuilder {
135    pub(crate) fn empty() -> Self {
136        Self::create_empty()
137    }
138}
139
140/// Error type for DeletePayloadPointsBuilder
141#[non_exhaustive]
142#[derive(Debug)]
143pub enum DeletePayloadPointsBuilderError {
144    /// Uninitialized field
145    UninitializedField(&'static str),
146    /// Custom validation error
147    ValidationError(String),
148}
149
150// Implementing the Display trait for better error messages
151impl std::fmt::Display for DeletePayloadPointsBuilderError {
152    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
153        match self {
154            Self::UninitializedField(field) => {
155                write!(f, "`{field}` must be initialized")
156            }
157            Self::ValidationError(error) => write!(f, "{error}"),
158        }
159    }
160}
161
162// Implementing the Error trait
163impl std::error::Error for DeletePayloadPointsBuilderError {}
164
165// Implementing From trait for conversion from UninitializedFieldError
166impl From<derive_builder::UninitializedFieldError> for DeletePayloadPointsBuilderError {
167    fn from(error: derive_builder::UninitializedFieldError) -> Self {
168        Self::UninitializedField(error.field_name())
169    }
170}
171
172// Implementing From trait for conversion from String
173impl From<String> for DeletePayloadPointsBuilderError {
174    fn from(error: String) -> Self {
175        Self::ValidationError(error)
176    }
177}