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