Skip to main content

qdrant_client/builders/
bool_index_params_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct BoolIndexParamsBuilder {
5    /// If true - store index on disk.
6    pub(crate) on_disk: Option<Option<bool>>,
7    /// If true - enable HNSW index for this field.
8    pub(crate) enable_hnsw: Option<Option<bool>>,
9}
10
11impl Default for BoolIndexParamsBuilder {
12    fn default() -> Self {
13        Self::new()
14    }
15}
16
17impl BoolIndexParamsBuilder {
18    pub fn new() -> Self {
19        Self::create_empty()
20    }
21
22    /// If true - store index on disk.
23    pub fn on_disk(self, value: bool) -> Self {
24        let mut new = self;
25        new.on_disk = Option::Some(Option::Some(value));
26        new
27    }
28    /// If true - enable HNSW index for this field.
29    pub fn enable_hnsw(self, value: bool) -> Self {
30        let mut new = self;
31        new.enable_hnsw = Option::Some(Option::Some(value));
32        new
33    }
34
35    fn build_inner(self) -> Result<BoolIndexParams, std::convert::Infallible> {
36        Ok(BoolIndexParams {
37            on_disk: self.on_disk.unwrap_or_default(),
38            enable_hnsw: self.enable_hnsw.unwrap_or_default(),
39        })
40    }
41    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
42    fn create_empty() -> Self {
43        Self {
44            on_disk: core::default::Default::default(),
45            enable_hnsw: core::default::Default::default(),
46        }
47    }
48}
49
50impl From<BoolIndexParamsBuilder> for BoolIndexParams {
51    fn from(value: BoolIndexParamsBuilder) -> Self {
52        value.build_inner().unwrap_or_else(|_| {
53            panic!(
54                "Failed to convert {0} to {1}",
55                "BoolIndexParamsBuilder", "BoolIndexParams"
56            )
57        })
58    }
59}
60
61impl BoolIndexParamsBuilder {
62    /// Builds the desired type. Can often be omitted.
63    pub fn build(self) -> BoolIndexParams {
64        self.build_inner().unwrap_or_else(|_| {
65            panic!(
66                "Failed to build {0} into {1}",
67                "BoolIndexParamsBuilder", "BoolIndexParams"
68            )
69        })
70    }
71}