qdrant_client/builders/
count_points_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4pub struct CountPointsBuilder {
5    /// Name of the collection
6    pub(crate) collection_name: Option<String>,
7    /// Filter conditions - return only those points that satisfy the specified conditions
8    pub(crate) filter: Option<Option<Filter>>,
9    /// If `true` - return exact count, if `false` - return approximate count
10    pub(crate) exact: Option<Option<bool>>,
11    /// Options for specifying read consistency guarantees
12    read_consistency: Option<read_consistency::Value>,
13    /// Specify in which shards to look for the points, if not specified - look in all shards
14    pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
15    /// If set, overrides global timeout setting for this request. Unit is seconds.
16    pub(crate) timeout: Option<Option<u64>>,
17}
18
19impl CountPointsBuilder {
20    /// Name of the collection
21    #[allow(unused_mut)]
22    pub fn collection_name(self, value: String) -> Self {
23        let mut new = self;
24        new.collection_name = Option::Some(value);
25        new
26    }
27    /// Filter conditions - return only those points that satisfy the specified conditions
28    #[allow(unused_mut)]
29    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    /// If `true` - return exact count, if `false` - return approximate count
35    #[allow(unused_mut)]
36    pub fn exact(self, value: bool) -> Self {
37        let mut new = self;
38        new.exact = Option::Some(Option::Some(value));
39        new
40    }
41    /// Options for specifying read consistency guarantees
42    #[allow(unused_mut)]
43    pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
44        self,
45        value: VALUE,
46    ) -> Self {
47        let mut new = self;
48        new.read_consistency = Option::Some(value.into());
49        new
50    }
51    /// Specify in which shards to look for the points, if not specified - look in all shards
52    #[allow(unused_mut)]
53    pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
54        self,
55        value: VALUE,
56    ) -> Self {
57        let mut new = self;
58        new.shard_key_selector = Option::Some(Option::Some(value.into()));
59        new
60    }
61    /// If set, overrides global timeout setting for this request. Unit is seconds.
62    #[allow(unused_mut)]
63    pub fn timeout(self, value: u64) -> Self {
64        let mut new = self;
65        new.timeout = Option::Some(Option::Some(value));
66        new
67    }
68
69    fn build_inner(self) -> Result<CountPoints, CountPointsBuilderError> {
70        Ok(CountPoints {
71            collection_name: match self.collection_name {
72                Some(value) => value,
73                None => {
74                    return Result::Err(core::convert::Into::into(
75                        ::derive_builder::UninitializedFieldError::from("collection_name"),
76                    ));
77                }
78            },
79            filter: self.filter.unwrap_or_default(),
80            exact: self.exact.unwrap_or_default(),
81            read_consistency: { convert_option(&self.read_consistency) },
82            shard_key_selector: self.shard_key_selector.unwrap_or_default(),
83            timeout: self.timeout.unwrap_or_default(),
84        })
85    }
86    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
87    fn create_empty() -> Self {
88        Self {
89            collection_name: core::default::Default::default(),
90            filter: core::default::Default::default(),
91            exact: core::default::Default::default(),
92            read_consistency: core::default::Default::default(),
93            shard_key_selector: core::default::Default::default(),
94            timeout: core::default::Default::default(),
95        }
96    }
97}
98
99impl From<CountPointsBuilder> for CountPoints {
100    fn from(value: CountPointsBuilder) -> Self {
101        value.build_inner().unwrap_or_else(|_| {
102            panic!(
103                "Failed to convert {0} to {1}",
104                "CountPointsBuilder", "CountPoints"
105            )
106        })
107    }
108}
109
110impl CountPointsBuilder {
111    /// Builds the desired type. Can often be omitted.
112    pub fn build(self) -> CountPoints {
113        self.build_inner().unwrap_or_else(|_| {
114            panic!(
115                "Failed to build {0} into {1}",
116                "CountPointsBuilder", "CountPoints"
117            )
118        })
119    }
120}
121
122impl CountPointsBuilder {
123    pub(crate) fn empty() -> Self {
124        Self::create_empty()
125    }
126}
127
128/// Error type for CountPointsBuilder
129#[non_exhaustive]
130#[derive(Debug)]
131pub enum CountPointsBuilderError {
132    /// Uninitialized field
133    UninitializedField(&'static str),
134    /// Custom validation error
135    ValidationError(String),
136}
137
138// Implementing the Display trait for better error messages
139impl std::fmt::Display for CountPointsBuilderError {
140    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
141        match self {
142            Self::UninitializedField(field) => {
143                write!(f, "`{}` must be initialized", field)
144            }
145            Self::ValidationError(error) => write!(f, "{}", error),
146        }
147    }
148}
149
150// Implementing the Error trait
151impl std::error::Error for CountPointsBuilderError {}
152
153// Implementing From trait for conversion from UninitializedFieldError
154impl From<derive_builder::UninitializedFieldError> for CountPointsBuilderError {
155    fn from(error: derive_builder::UninitializedFieldError) -> Self {
156        Self::UninitializedField(error.field_name())
157    }
158}
159
160// Implementing From trait for conversion from String
161impl From<String> for CountPointsBuilderError {
162    fn from(error: String) -> Self {
163        Self::ValidationError(error)
164    }
165}