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