Skip to main content

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