qdrant_client/builders/
facet_counts_builder.rs1use crate::qdrant::*;
2
3pub struct FacetCountsBuilder {
4 pub(crate) collection_name: Option<String>,
6 pub(crate) key: Option<String>,
8 pub(crate) filter: Option<Option<Filter>>,
10 pub(crate) limit: Option<Option<u64>>,
12 pub(crate) exact: Option<Option<bool>>,
14 pub(crate) timeout: Option<Option<u64>>,
16 pub(crate) read_consistency: Option<Option<ReadConsistency>>,
18 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
20}
21
22impl FacetCountsBuilder {
23 #[allow(unused_mut)]
25 pub fn collection_name(self, value: String) -> Self {
26 let mut new = self;
27 new.collection_name = Option::Some(value);
28 new
29 }
30 #[allow(unused_mut)]
32 pub fn key(self, value: String) -> Self {
33 let mut new = self;
34 new.key = Option::Some(value);
35 new
36 }
37 #[allow(unused_mut)]
39 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
40 let mut new = self;
41 new.filter = Option::Some(Option::Some(value.into()));
42 new
43 }
44 #[allow(unused_mut)]
46 pub fn limit(self, value: u64) -> Self {
47 let mut new = self;
48 new.limit = Option::Some(Option::Some(value));
49 new
50 }
51 #[allow(unused_mut)]
53 pub fn exact(self, value: bool) -> Self {
54 let mut new = self;
55 new.exact = Option::Some(Option::Some(value));
56 new
57 }
58 #[allow(unused_mut)]
60 pub fn timeout(self, value: u64) -> Self {
61 let mut new = self;
62 new.timeout = Option::Some(Option::Some(value));
63 new
64 }
65 #[allow(unused_mut)]
67 pub fn read_consistency<VALUE: core::convert::Into<ReadConsistency>>(
68 self,
69 value: VALUE,
70 ) -> Self {
71 let mut new = self;
72 new.read_consistency = Option::Some(Option::Some(value.into()));
73 new
74 }
75 #[allow(unused_mut)]
77 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
78 self,
79 value: VALUE,
80 ) -> Self {
81 let mut new = self;
82 new.shard_key_selector = Option::Some(Option::Some(value.into()));
83 new
84 }
85
86 fn build_inner(self) -> Result<FacetCounts, FacetCountsBuilderError> {
87 Ok(FacetCounts {
88 collection_name: match self.collection_name {
89 Some(value) => value,
90 None => {
91 return Result::Err(core::convert::Into::into(
92 ::derive_builder::UninitializedFieldError::from("collection_name"),
93 ));
94 }
95 },
96 key: match self.key {
97 Some(value) => value,
98 None => {
99 return Result::Err(core::convert::Into::into(
100 ::derive_builder::UninitializedFieldError::from("key"),
101 ));
102 }
103 },
104 filter: self.filter.unwrap_or_default(),
105 limit: self.limit.unwrap_or_default(),
106 exact: self.exact.unwrap_or_default(),
107 timeout: self.timeout.unwrap_or_default(),
108 read_consistency: self.read_consistency.unwrap_or_default(),
109 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
110 })
111 }
112 fn create_empty() -> Self {
114 Self {
115 collection_name: core::default::Default::default(),
116 key: core::default::Default::default(),
117 filter: core::default::Default::default(),
118 limit: core::default::Default::default(),
119 exact: core::default::Default::default(),
120 timeout: core::default::Default::default(),
121 read_consistency: core::default::Default::default(),
122 shard_key_selector: core::default::Default::default(),
123 }
124 }
125}
126
127impl From<FacetCountsBuilder> for FacetCounts {
128 fn from(value: FacetCountsBuilder) -> Self {
129 value.build_inner().unwrap_or_else(|_| {
130 panic!(
131 "Failed to convert {0} to {1}",
132 "FacetCountsBuilder", "FacetCounts"
133 )
134 })
135 }
136}
137
138impl FacetCountsBuilder {
139 pub fn build(self) -> FacetCounts {
141 self.build_inner().unwrap_or_else(|_| {
142 panic!(
143 "Failed to build {0} into {1}",
144 "FacetCountsBuilder", "FacetCounts"
145 )
146 })
147 }
148}
149
150impl FacetCountsBuilder {
151 pub(crate) fn empty() -> Self {
152 Self::create_empty()
153 }
154}
155
156#[non_exhaustive]
158#[derive(Debug)]
159pub enum FacetCountsBuilderError {
160 UninitializedField(&'static str),
162 ValidationError(String),
164}
165
166impl From<derive_builder::UninitializedFieldError> for FacetCountsBuilderError {
168 fn from(s: derive_builder::UninitializedFieldError) -> Self {
169 Self::UninitializedField(s.field_name())
170 }
171}
172
173impl From<String> for FacetCountsBuilderError {
175 fn from(s: String) -> Self {
176 Self::ValidationError(s)
177 }
178}
179
180impl std::fmt::Display for FacetCountsBuilderError {
182 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183 match self {
184 Self::UninitializedField(ref field) => {
185 write!(f, "`{}` must be initialized", field)
186 }
187 Self::ValidationError(ref error) => write!(f, "{}", error),
188 }
189 }
190}
191
192impl std::error::Error for FacetCountsBuilderError {}