qdrant_client/builders/
scroll_points_builder.rs1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[must_use]
5#[derive(Clone)]
6pub struct ScrollPointsBuilder {
7 pub(crate) collection_name: Option<String>,
8 pub(crate) filter: Option<Option<Filter>>,
10 pub(crate) offset: Option<Option<PointId>>,
12 pub(crate) limit: Option<Option<u32>>,
14 with_payload: Option<with_payload_selector::SelectorOptions>,
16 with_vectors: Option<with_vectors_selector::SelectorOptions>,
18 read_consistency: Option<read_consistency::Value>,
20 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
22 pub(crate) order_by: Option<Option<OrderBy>>,
24 pub(crate) timeout: Option<Option<u64>>,
26}
27
28impl ScrollPointsBuilder {
29 pub fn collection_name(self, value: String) -> Self {
30 let mut new = self;
31 new.collection_name = Option::Some(value);
32 new
33 }
34 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
36 let mut new = self;
37 new.filter = Option::Some(Option::Some(value.into()));
38 new
39 }
40 pub fn offset<VALUE: core::convert::Into<PointId>>(self, value: VALUE) -> Self {
42 let mut new = self;
43 new.offset = Option::Some(Option::Some(value.into()));
44 new
45 }
46 pub fn limit(self, value: u32) -> Self {
48 let mut new = self;
49 new.limit = Option::Some(Option::Some(value));
50 new
51 }
52 pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
54 self,
55 value: VALUE,
56 ) -> Self {
57 let mut new = self;
58 new.with_payload = Option::Some(value.into());
59 new
60 }
61 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
63 self,
64 value: VALUE,
65 ) -> Self {
66 let mut new = self;
67 new.with_vectors = Option::Some(value.into());
68 new
69 }
70 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
72 self,
73 value: VALUE,
74 ) -> Self {
75 let mut new = self;
76 new.read_consistency = Option::Some(value.into());
77 new
78 }
79 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
81 self,
82 value: VALUE,
83 ) -> Self {
84 let mut new = self;
85 new.shard_key_selector = Option::Some(Option::Some(value.into()));
86 new
87 }
88 pub fn order_by<VALUE: core::convert::Into<OrderBy>>(self, value: VALUE) -> Self {
90 let mut new = self;
91 new.order_by = Option::Some(Option::Some(value.into()));
92 new
93 }
94 pub fn timeout(self, value: u64) -> Self {
96 let mut new = self;
97 new.timeout = Option::Some(Option::Some(value));
98 new
99 }
100
101 fn build_inner(self) -> Result<ScrollPoints, ScrollPointsBuilderError> {
102 Ok(ScrollPoints {
103 collection_name: match self.collection_name {
104 Some(value) => value,
105 None => {
106 return Result::Err(core::convert::Into::into(
107 ::derive_builder::UninitializedFieldError::from("collection_name"),
108 ));
109 }
110 },
111 filter: self.filter.unwrap_or_default(),
112 offset: self.offset.unwrap_or_default(),
113 limit: self.limit.unwrap_or_default(),
114 with_payload: { convert_option(&self.with_payload) },
115 with_vectors: { convert_option(&self.with_vectors) },
116 read_consistency: { convert_option(&self.read_consistency) },
117 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
118 order_by: self.order_by.unwrap_or_default(),
119 timeout: self.timeout.unwrap_or_default(),
120 })
121 }
122 fn create_empty() -> Self {
124 Self {
125 collection_name: core::default::Default::default(),
126 filter: core::default::Default::default(),
127 offset: core::default::Default::default(),
128 limit: core::default::Default::default(),
129 with_payload: core::default::Default::default(),
130 with_vectors: core::default::Default::default(),
131 read_consistency: core::default::Default::default(),
132 shard_key_selector: core::default::Default::default(),
133 order_by: core::default::Default::default(),
134 timeout: core::default::Default::default(),
135 }
136 }
137}
138
139impl From<ScrollPointsBuilder> for ScrollPoints {
140 fn from(value: ScrollPointsBuilder) -> Self {
141 value.build_inner().unwrap_or_else(|_| {
142 panic!(
143 "Failed to convert {0} to {1}",
144 "ScrollPointsBuilder", "ScrollPoints"
145 )
146 })
147 }
148}
149
150impl ScrollPointsBuilder {
151 pub fn build(self) -> ScrollPoints {
153 self.build_inner().unwrap_or_else(|_| {
154 panic!(
155 "Failed to build {0} into {1}",
156 "ScrollPointsBuilder", "ScrollPoints"
157 )
158 })
159 }
160}
161
162impl ScrollPointsBuilder {
163 pub(crate) fn empty() -> Self {
164 Self::create_empty()
165 }
166}
167
168#[non_exhaustive]
169#[derive(Debug)]
170pub enum ScrollPointsBuilderError {
171 UninitializedField(&'static str),
173 ValidationError(String),
175}
176
177impl std::fmt::Display for ScrollPointsBuilderError {
179 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
180 match self {
181 Self::UninitializedField(field) => {
182 write!(f, "`{field}` must be initialized")
183 }
184 Self::ValidationError(error) => write!(f, "{error}"),
185 }
186 }
187}
188
189impl std::error::Error for ScrollPointsBuilderError {}
191
192impl From<derive_builder::UninitializedFieldError> for ScrollPointsBuilderError {
194 fn from(error: derive_builder::UninitializedFieldError) -> Self {
195 Self::UninitializedField(error.field_name())
196 }
197}
198
199impl From<String> for ScrollPointsBuilderError {
201 fn from(error: String) -> Self {
202 Self::ValidationError(error)
203 }
204}