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