Skip to main content

qdrant_client/builders/
clear_payload_points_builder.rs

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