qdrant_client/builders/
count_points_builder.rs

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