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