qdrant_client/builders/
upsert_points_builder.rs1use crate::qdrant::*;
2
3#[must_use]
4#[derive(Clone)]
5pub struct UpsertPointsBuilder {
6 pub(crate) collection_name: Option<String>,
8 pub(crate) wait: Option<Option<bool>>,
10 pub(crate) points: Option<Vec<PointStruct>>,
11 pub(crate) ordering: Option<Option<WriteOrdering>>,
13 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
15 pub(crate) update_filter: Option<Option<Filter>>,
17 pub(crate) timeout: Option<Option<u64>>,
19 pub(crate) update_mode: Option<Option<i32>>,
21}
22
23impl UpsertPointsBuilder {
24 pub fn collection_name(self, value: String) -> Self {
26 let mut new = self;
27 new.collection_name = Option::Some(value);
28 new
29 }
30 pub fn wait(self, value: bool) -> Self {
32 let mut new = self;
33 new.wait = Option::Some(Option::Some(value));
34 new
35 }
36 pub fn points(self, value: Vec<PointStruct>) -> Self {
37 let mut new = self;
38 new.points = Option::Some(value);
39 new
40 }
41 pub fn ordering<VALUE: core::convert::Into<WriteOrdering>>(self, value: VALUE) -> Self {
43 let mut new = self;
44 new.ordering = Option::Some(Option::Some(value.into()));
45 new
46 }
47 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
49 self,
50 value: VALUE,
51 ) -> Self {
52 let mut new = self;
53 new.shard_key_selector = Option::Some(Option::Some(value.into()));
54 new
55 }
56 pub fn update_filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
58 let mut new = self;
59 new.update_filter = Option::Some(Option::Some(value.into()));
60 new
61 }
62 pub fn timeout(self, value: u64) -> Self {
64 let mut new = self;
65 new.timeout = Option::Some(Option::Some(value));
66 new
67 }
68 pub fn update_mode(self, value: UpdateMode) -> Self {
70 let mut new = self;
71 new.update_mode = Option::Some(Option::Some(value.into()));
72 new
73 }
74
75 fn build_inner(self) -> Result<UpsertPoints, UpsertPointsBuilderError> {
76 Ok(UpsertPoints {
77 collection_name: match self.collection_name {
78 Some(value) => value,
79 None => {
80 return Result::Err(core::convert::Into::into(
81 ::derive_builder::UninitializedFieldError::from("collection_name"),
82 ));
83 }
84 },
85 wait: self.wait.unwrap_or_default(),
86 points: match self.points {
87 Some(value) => value,
88 None => {
89 return Result::Err(core::convert::Into::into(
90 ::derive_builder::UninitializedFieldError::from("points"),
91 ));
92 }
93 },
94 ordering: self.ordering.unwrap_or_default(),
95 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
96 update_filter: self.update_filter.unwrap_or_default(),
97 timeout: self.timeout.unwrap_or_default(),
98 update_mode: self.update_mode.unwrap_or_default(),
99 })
100 }
101 fn create_empty() -> Self {
103 Self {
104 collection_name: core::default::Default::default(),
105 wait: core::default::Default::default(),
106 points: core::default::Default::default(),
107 ordering: core::default::Default::default(),
108 shard_key_selector: core::default::Default::default(),
109 update_filter: core::default::Default::default(),
110 timeout: core::default::Default::default(),
111 update_mode: core::default::Default::default(),
112 }
113 }
114}
115
116impl From<UpsertPointsBuilder> for UpsertPoints {
117 fn from(value: UpsertPointsBuilder) -> Self {
118 value.build_inner().unwrap_or_else(|_| {
119 panic!(
120 "Failed to convert {0} to {1}",
121 "UpsertPointsBuilder", "UpsertPoints"
122 )
123 })
124 }
125}
126
127impl UpsertPointsBuilder {
128 pub fn build(self) -> UpsertPoints {
130 self.build_inner().unwrap_or_else(|_| {
131 panic!(
132 "Failed to build {0} into {1}",
133 "UpsertPointsBuilder", "UpsertPoints"
134 )
135 })
136 }
137}
138
139impl UpsertPointsBuilder {
140 pub(crate) fn empty() -> Self {
141 Self::create_empty()
142 }
143}
144
145#[non_exhaustive]
146#[derive(Debug)]
147pub enum UpsertPointsBuilderError {
148 UninitializedField(&'static str),
150 ValidationError(String),
152}
153
154impl std::fmt::Display for UpsertPointsBuilderError {
156 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
157 match self {
158 Self::UninitializedField(field) => {
159 write!(f, "`{field}` must be initialized")
160 }
161 Self::ValidationError(error) => write!(f, "{error}"),
162 }
163 }
164}
165
166impl std::error::Error for UpsertPointsBuilderError {}
168
169impl From<derive_builder::UninitializedFieldError> for UpsertPointsBuilderError {
171 fn from(error: derive_builder::UninitializedFieldError) -> Self {
172 Self::UninitializedField(error.field_name())
173 }
174}
175
176impl From<String> for UpsertPointsBuilderError {
178 fn from(error: String) -> Self {
179 Self::ValidationError(error)
180 }
181}