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    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    /// New payload values
36    pub fn payload(self, value: ::std::collections::HashMap<String, Value>) -> Self {
37        let mut new = self;
38        new.payload = 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    /// Option for indicate property of payload
66    pub fn key<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
67        let mut new = self;
68        new.key = Option::Some(Option::Some(value.into()));
69        new
70    }
71
72    fn build_inner(self) -> Result<SetPayloadPoints, SetPayloadPointsBuilderError> {
73        Ok(SetPayloadPoints {
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            payload: match self.payload {
84                Some(value) => value,
85                None => {
86                    return Result::Err(core::convert::Into::into(
87                        ::derive_builder::UninitializedFieldError::from("payload"),
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            key: self.key.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            payload: 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            key: core::default::Default::default(),
107        }
108    }
109}
110
111impl From<SetPayloadPointsBuilder> for SetPayloadPoints {
112    fn from(value: SetPayloadPointsBuilder) -> Self {
113        value.build_inner().unwrap_or_else(|_| {
114            panic!(
115                "Failed to convert {0} to {1}",
116                "SetPayloadPointsBuilder", "SetPayloadPoints"
117            )
118        })
119    }
120}
121
122impl SetPayloadPointsBuilder {
123    /// Builds the desired type. Can often be omitted.
124    pub fn build(self) -> SetPayloadPoints {
125        self.build_inner().unwrap_or_else(|_| {
126            panic!(
127                "Failed to build {0} into {1}",
128                "SetPayloadPointsBuilder", "SetPayloadPoints"
129            )
130        })
131    }
132}
133
134impl SetPayloadPointsBuilder {
135    pub(crate) fn empty() -> Self {
136        Self::create_empty()
137    }
138}
139
140#[non_exhaustive]
141#[derive(Debug)]
142pub enum SetPayloadPointsBuilderError {
143    /// Uninitialized field
144    UninitializedField(&'static str),
145    /// Custom validation error
146    ValidationError(String),
147}
148
149// Implementing the Display trait for better error messages
150impl std::fmt::Display for SetPayloadPointsBuilderError {
151    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
152        match self {
153            Self::UninitializedField(field) => {
154                write!(f, "`{field}` must be initialized")
155            }
156            Self::ValidationError(error) => write!(f, "{error}"),
157        }
158    }
159}
160
161// Implementing the Error trait
162impl std::error::Error for SetPayloadPointsBuilderError {}
163
164// Implementing From trait for conversion from UninitializedFieldError
165impl From<derive_builder::UninitializedFieldError> for SetPayloadPointsBuilderError {
166    fn from(error: derive_builder::UninitializedFieldError) -> Self {
167        Self::UninitializedField(error.field_name())
168    }
169}
170
171// Implementing From trait for conversion from String
172impl From<String> for SetPayloadPointsBuilderError {
173    fn from(error: String) -> Self {
174        Self::ValidationError(error)
175    }
176}