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 pub fn collection_name(self, value: String) -> Self {
26 let mut new = self;
27 new.collection_name = Option::Some(value);
28 new
29 }
30 pub fn key(self, value: String) -> Self {
32 let mut new = self;
33 new.key = Option::Some(value);
34 new
35 }
36 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
38 let mut new = self;
39 new.filter = Option::Some(Option::Some(value.into()));
40 new
41 }
42 pub fn limit(self, value: u64) -> Self {
44 let mut new = self;
45 new.limit = Option::Some(Option::Some(value));
46 new
47 }
48 pub fn exact(self, value: bool) -> Self {
50 let mut new = self;
51 new.exact = Option::Some(Option::Some(value));
52 new
53 }
54 pub fn timeout(self, value: u64) -> Self {
56 let mut new = self;
57 new.timeout = Option::Some(Option::Some(value));
58 new
59 }
60 pub fn read_consistency<VALUE: core::convert::Into<ReadConsistency>>(
62 self,
63 value: VALUE,
64 ) -> Self {
65 let mut new = self;
66 new.read_consistency = Option::Some(Option::Some(value.into()));
67 new
68 }
69 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
71 self,
72 value: VALUE,
73 ) -> Self {
74 let mut new = self;
75 new.shard_key_selector = Option::Some(Option::Some(value.into()));
76 new
77 }
78
79 fn build_inner(self) -> Result<FacetCounts, FacetCountsBuilderError> {
80 Ok(FacetCounts {
81 collection_name: match self.collection_name {
82 Some(value) => value,
83 None => {
84 return Result::Err(core::convert::Into::into(
85 ::derive_builder::UninitializedFieldError::from("collection_name"),
86 ));
87 }
88 },
89 key: match self.key {
90 Some(value) => value,
91 None => {
92 return Result::Err(core::convert::Into::into(
93 ::derive_builder::UninitializedFieldError::from("key"),
94 ));
95 }
96 },
97 filter: self.filter.unwrap_or_default(),
98 limit: self.limit.unwrap_or_default(),
99 exact: self.exact.unwrap_or_default(),
100 timeout: self.timeout.unwrap_or_default(),
101 read_consistency: self.read_consistency.unwrap_or_default(),
102 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
103 })
104 }
105 fn create_empty() -> Self {
107 Self {
108 collection_name: core::default::Default::default(),
109 key: core::default::Default::default(),
110 filter: core::default::Default::default(),
111 limit: core::default::Default::default(),
112 exact: core::default::Default::default(),
113 timeout: core::default::Default::default(),
114 read_consistency: core::default::Default::default(),
115 shard_key_selector: core::default::Default::default(),
116 }
117 }
118}
119
120impl From<FacetCountsBuilder> for FacetCounts {
121 fn from(value: FacetCountsBuilder) -> Self {
122 value.build_inner().unwrap_or_else(|_| {
123 panic!(
124 "Failed to convert {0} to {1}",
125 "FacetCountsBuilder", "FacetCounts"
126 )
127 })
128 }
129}
130
131impl FacetCountsBuilder {
132 pub fn build(self) -> FacetCounts {
134 self.build_inner().unwrap_or_else(|_| {
135 panic!(
136 "Failed to build {0} into {1}",
137 "FacetCountsBuilder", "FacetCounts"
138 )
139 })
140 }
141}
142
143impl FacetCountsBuilder {
144 pub(crate) fn empty() -> Self {
145 Self::create_empty()
146 }
147}
148
149#[non_exhaustive]
151#[derive(Debug)]
152pub enum FacetCountsBuilderError {
153 UninitializedField(&'static str),
155 ValidationError(String),
157}
158
159impl From<derive_builder::UninitializedFieldError> for FacetCountsBuilderError {
161 fn from(s: derive_builder::UninitializedFieldError) -> Self {
162 Self::UninitializedField(s.field_name())
163 }
164}
165
166impl From<String> for FacetCountsBuilderError {
168 fn from(s: String) -> Self {
169 Self::ValidationError(s)
170 }
171}
172
173impl std::fmt::Display for FacetCountsBuilderError {
175 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
176 match self {
177 Self::UninitializedField(ref field) => {
178 write!(f, "`{field}` must be initialized")
179 }
180 Self::ValidationError(ref error) => write!(f, "{error}"),
181 }
182 }
183}
184
185impl std::error::Error for FacetCountsBuilderError {}