qdrant_client/builders/
set_payload_points_builder.rs

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