Skip to main content

qdrant_client/builders/
geo_index_params_builder.rs

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