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}
15
16impl UpsertPointsBuilder {
17 #[allow(unused_mut)]
19 pub fn collection_name(self, value: String) -> Self {
20 let mut new = self;
21 new.collection_name = Option::Some(value);
22 new
23 }
24 #[allow(unused_mut)]
26 pub fn wait(self, value: bool) -> Self {
27 let mut new = self;
28 new.wait = Option::Some(Option::Some(value));
29 new
30 }
31 #[allow(unused_mut)]
32 pub fn points(self, value: Vec<PointStruct>) -> Self {
33 let mut new = self;
34 new.points = Option::Some(value);
35 new
36 }
37 #[allow(unused_mut)]
39 pub fn ordering<VALUE: core::convert::Into<WriteOrdering>>(self, value: VALUE) -> Self {
40 let mut new = self;
41 new.ordering = Option::Some(Option::Some(value.into()));
42 new
43 }
44 #[allow(unused_mut)]
46 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
47 self,
48 value: VALUE,
49 ) -> Self {
50 let mut new = self;
51 new.shard_key_selector = Option::Some(Option::Some(value.into()));
52 new
53 }
54
55 fn build_inner(self) -> Result<UpsertPoints, UpsertPointsBuilderError> {
56 Ok(UpsertPoints {
57 collection_name: match self.collection_name {
58 Some(value) => value,
59 None => {
60 return Result::Err(core::convert::Into::into(
61 ::derive_builder::UninitializedFieldError::from("collection_name"),
62 ));
63 }
64 },
65 wait: self.wait.unwrap_or_default(),
66 points: match self.points {
67 Some(value) => value,
68 None => {
69 return Result::Err(core::convert::Into::into(
70 ::derive_builder::UninitializedFieldError::from("points"),
71 ));
72 }
73 },
74 ordering: self.ordering.unwrap_or_default(),
75 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
76 })
77 }
78 fn create_empty() -> Self {
80 Self {
81 collection_name: core::default::Default::default(),
82 wait: core::default::Default::default(),
83 points: core::default::Default::default(),
84 ordering: core::default::Default::default(),
85 shard_key_selector: core::default::Default::default(),
86 }
87 }
88}
89
90impl From<UpsertPointsBuilder> for UpsertPoints {
91 fn from(value: UpsertPointsBuilder) -> Self {
92 value.build_inner().unwrap_or_else(|_| {
93 panic!(
94 "Failed to convert {0} to {1}",
95 "UpsertPointsBuilder", "UpsertPoints"
96 )
97 })
98 }
99}
100
101impl UpsertPointsBuilder {
102 pub fn build(self) -> UpsertPoints {
104 self.build_inner().unwrap_or_else(|_| {
105 panic!(
106 "Failed to build {0} into {1}",
107 "UpsertPointsBuilder", "UpsertPoints"
108 )
109 })
110 }
111}
112
113impl UpsertPointsBuilder {
114 pub(crate) fn empty() -> Self {
115 Self::create_empty()
116 }
117}
118
119#[non_exhaustive]
120#[derive(Debug)]
121pub enum UpsertPointsBuilderError {
122 UninitializedField(&'static str),
124 ValidationError(String),
126}
127
128impl std::fmt::Display for UpsertPointsBuilderError {
130 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
131 match self {
132 Self::UninitializedField(field) => {
133 write!(f, "`{field}` must be initialized")
134 }
135 Self::ValidationError(error) => write!(f, "{error}"),
136 }
137 }
138}
139
140impl std::error::Error for UpsertPointsBuilderError {}
142
143impl From<derive_builder::UninitializedFieldError> for UpsertPointsBuilderError {
145 fn from(error: derive_builder::UninitializedFieldError) -> Self {
146 Self::UninitializedField(error.field_name())
147 }
148}
149
150impl From<String> for UpsertPointsBuilderError {
152 fn from(error: String) -> Self {
153 Self::ValidationError(error)
154 }
155}