qdrant_client/builders/
count_points_builder.rs1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4pub struct CountPointsBuilder {
5 pub(crate) collection_name: Option<String>,
7 pub(crate) filter: Option<Option<Filter>>,
9 pub(crate) exact: Option<Option<bool>>,
11 read_consistency: Option<read_consistency::Value>,
13 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
15 pub(crate) timeout: Option<Option<u64>>,
17}
18
19impl CountPointsBuilder {
20 #[allow(unused_mut)]
22 pub fn collection_name(self, value: String) -> Self {
23 let mut new = self;
24 new.collection_name = Option::Some(value);
25 new
26 }
27 #[allow(unused_mut)]
29 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
30 let mut new = self;
31 new.filter = Option::Some(Option::Some(value.into()));
32 new
33 }
34 #[allow(unused_mut)]
36 pub fn exact(self, value: bool) -> Self {
37 let mut new = self;
38 new.exact = Option::Some(Option::Some(value));
39 new
40 }
41 #[allow(unused_mut)]
43 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
44 self,
45 value: VALUE,
46 ) -> Self {
47 let mut new = self;
48 new.read_consistency = Option::Some(value.into());
49 new
50 }
51 #[allow(unused_mut)]
53 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
54 self,
55 value: VALUE,
56 ) -> Self {
57 let mut new = self;
58 new.shard_key_selector = Option::Some(Option::Some(value.into()));
59 new
60 }
61 #[allow(unused_mut)]
63 pub fn timeout(self, value: u64) -> Self {
64 let mut new = self;
65 new.timeout = Option::Some(Option::Some(value));
66 new
67 }
68
69 fn build_inner(self) -> Result<CountPoints, CountPointsBuilderError> {
70 Ok(CountPoints {
71 collection_name: match self.collection_name {
72 Some(value) => value,
73 None => {
74 return Result::Err(core::convert::Into::into(
75 ::derive_builder::UninitializedFieldError::from("collection_name"),
76 ));
77 }
78 },
79 filter: self.filter.unwrap_or_default(),
80 exact: self.exact.unwrap_or_default(),
81 read_consistency: { convert_option(&self.read_consistency) },
82 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
83 timeout: self.timeout.unwrap_or_default(),
84 })
85 }
86 fn create_empty() -> Self {
88 Self {
89 collection_name: core::default::Default::default(),
90 filter: core::default::Default::default(),
91 exact: core::default::Default::default(),
92 read_consistency: core::default::Default::default(),
93 shard_key_selector: core::default::Default::default(),
94 timeout: core::default::Default::default(),
95 }
96 }
97}
98
99impl From<CountPointsBuilder> for CountPoints {
100 fn from(value: CountPointsBuilder) -> Self {
101 value.build_inner().unwrap_or_else(|_| {
102 panic!(
103 "Failed to convert {0} to {1}",
104 "CountPointsBuilder", "CountPoints"
105 )
106 })
107 }
108}
109
110impl CountPointsBuilder {
111 pub fn build(self) -> CountPoints {
113 self.build_inner().unwrap_or_else(|_| {
114 panic!(
115 "Failed to build {0} into {1}",
116 "CountPointsBuilder", "CountPoints"
117 )
118 })
119 }
120}
121
122impl CountPointsBuilder {
123 pub(crate) fn empty() -> Self {
124 Self::create_empty()
125 }
126}
127
128#[non_exhaustive]
130#[derive(Debug)]
131pub enum CountPointsBuilderError {
132 UninitializedField(&'static str),
134 ValidationError(String),
136}
137
138impl std::fmt::Display for CountPointsBuilderError {
140 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
141 match self {
142 Self::UninitializedField(field) => {
143 write!(f, "`{}` must be initialized", field)
144 }
145 Self::ValidationError(error) => write!(f, "{}", error),
146 }
147 }
148}
149
150impl std::error::Error for CountPointsBuilderError {}
152
153impl From<derive_builder::UninitializedFieldError> for CountPointsBuilderError {
155 fn from(error: derive_builder::UninitializedFieldError) -> Self {
156 Self::UninitializedField(error.field_name())
157 }
158}
159
160impl From<String> for CountPointsBuilderError {
162 fn from(error: String) -> Self {
163 Self::ValidationError(error)
164 }
165}