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