qdrant_client/builders/
delete_points_builder.rs

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