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