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