qdrant_client/builders/
get_points_builder.rs1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4pub struct GetPointsBuilder {
5 pub(crate) collection_name: Option<String>,
7 pub(crate) ids: Option<Vec<PointId>>,
9 with_payload: Option<with_payload_selector::SelectorOptions>,
11 with_vectors: Option<with_vectors_selector::SelectorOptions>,
13 read_consistency: Option<read_consistency::Value>,
15 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
17 pub(crate) timeout: Option<Option<u64>>,
19}
20
21impl GetPointsBuilder {
22 #[allow(unused_mut)]
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 #[allow(unused_mut)]
31 pub fn ids(self, value: Vec<PointId>) -> Self {
32 let mut new = self;
33 new.ids = Option::Some(value);
34 new
35 }
36 #[allow(unused_mut)]
38 pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
39 self,
40 value: VALUE,
41 ) -> Self {
42 let mut new = self;
43 new.with_payload = Option::Some(value.into());
44 new
45 }
46 #[allow(unused_mut)]
48 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
49 self,
50 value: VALUE,
51 ) -> Self {
52 let mut new = self;
53 new.with_vectors = Option::Some(value.into());
54 new
55 }
56 #[allow(unused_mut)]
58 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
59 self,
60 value: VALUE,
61 ) -> Self {
62 let mut new = self;
63 new.read_consistency = Option::Some(value.into());
64 new
65 }
66 #[allow(unused_mut)]
68 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
69 self,
70 value: VALUE,
71 ) -> Self {
72 let mut new = self;
73 new.shard_key_selector = Option::Some(Option::Some(value.into()));
74 new
75 }
76 #[allow(unused_mut)]
78 pub fn timeout(self, value: u64) -> Self {
79 let mut new = self;
80 new.timeout = Option::Some(Option::Some(value));
81 new
82 }
83
84 fn build_inner(self) -> Result<GetPoints, GetPointsBuilderError> {
85 Ok(GetPoints {
86 collection_name: match self.collection_name {
87 Some(value) => value,
88 None => {
89 return Result::Err(core::convert::Into::into(
90 ::derive_builder::UninitializedFieldError::from("collection_name"),
91 ));
92 }
93 },
94 ids: match self.ids {
95 Some(value) => value,
96 None => {
97 return Result::Err(core::convert::Into::into(
98 ::derive_builder::UninitializedFieldError::from("ids"),
99 ));
100 }
101 },
102 with_payload: { convert_option(&self.with_payload) },
103 with_vectors: { convert_option(&self.with_vectors) },
104 read_consistency: { convert_option(&self.read_consistency) },
105 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
106 timeout: self.timeout.unwrap_or_default(),
107 })
108 }
109 fn create_empty() -> Self {
111 Self {
112 collection_name: core::default::Default::default(),
113 ids: core::default::Default::default(),
114 with_payload: core::default::Default::default(),
115 with_vectors: core::default::Default::default(),
116 read_consistency: core::default::Default::default(),
117 shard_key_selector: core::default::Default::default(),
118 timeout: core::default::Default::default(),
119 }
120 }
121}
122
123impl From<GetPointsBuilder> for GetPoints {
124 fn from(value: GetPointsBuilder) -> Self {
125 value.build_inner().unwrap_or_else(|_| {
126 panic!(
127 "Failed to convert {0} to {1}",
128 "GetPointsBuilder", "GetPoints"
129 )
130 })
131 }
132}
133
134impl GetPointsBuilder {
135 pub fn build(self) -> GetPoints {
137 self.build_inner().unwrap_or_else(|_| {
138 panic!(
139 "Failed to build {0} into {1}",
140 "GetPointsBuilder", "GetPoints"
141 )
142 })
143 }
144}
145
146impl GetPointsBuilder {
147 pub(crate) fn empty() -> Self {
148 Self::create_empty()
149 }
150}
151
152#[non_exhaustive]
154#[derive(Debug)]
155pub enum GetPointsBuilderError {
156 UninitializedField(&'static str),
158 ValidationError(String),
160}
161
162impl From<derive_builder::UninitializedFieldError> for GetPointsBuilderError {
164 fn from(s: derive_builder::UninitializedFieldError) -> Self {
165 Self::UninitializedField(s.field_name())
166 }
167}
168
169impl From<String> for GetPointsBuilderError {
171 fn from(s: String) -> Self {
172 Self::ValidationError(s)
173 }
174}
175
176impl std::fmt::Display for GetPointsBuilderError {
178 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
179 match self {
180 Self::UninitializedField(ref field) => {
181 write!(f, "`{}` must be initialized", field)
182 }
183 Self::ValidationError(ref error) => {
184 write!(f, "{}", error)
185 }
186 }
187 }
188}
189
190impl std::error::Error for GetPointsBuilderError {}