qdrant_client/builders/
integer_index_params_builder.rs1use crate::qdrant::*;
2
3#[must_use]
4#[derive(Clone)]
5pub struct IntegerIndexParamsBuilder {
6 pub(crate) lookup: Option<Option<bool>>,
8 pub(crate) range: Option<Option<bool>>,
10 pub(crate) is_principal: Option<Option<bool>>,
12 pub(crate) on_disk: Option<Option<bool>>,
14 pub(crate) enable_hnsw: Option<Option<bool>>,
16}
17
18impl IntegerIndexParamsBuilder {
19 pub fn new(lookup: bool, range: bool) -> Self {
20 Self::create_empty().lookup(lookup).range(range)
21 }
22
23 pub fn lookup<VALUE: core::convert::Into<bool>>(self, value: VALUE) -> Self {
25 let mut new = self;
26 new.lookup = Option::Some(Option::Some(value.into()));
27 new
28 }
29 pub fn range<VALUE: core::convert::Into<bool>>(self, value: VALUE) -> Self {
31 let mut new = self;
32 new.range = Option::Some(Option::Some(value.into()));
33 new
34 }
35 pub fn is_principal(self, value: bool) -> Self {
37 let mut new = self;
38 new.is_principal = Option::Some(Option::Some(value));
39 new
40 }
41 pub fn on_disk(self, value: bool) -> Self {
43 let mut new = self;
44 new.on_disk = Option::Some(Option::Some(value));
45 new
46 }
47 pub fn enable_hnsw(self, value: bool) -> Self {
49 let mut new = self;
50 new.enable_hnsw = Option::Some(Option::Some(value));
51 new
52 }
53
54 fn build_inner(self) -> Result<IntegerIndexParams, IntegerIndexParamsBuilderError> {
55 Ok(IntegerIndexParams {
56 lookup: self.lookup.unwrap_or_default(),
57 range: self.range.unwrap_or_default(),
58 is_principal: self.is_principal.unwrap_or_default(),
59 on_disk: self.on_disk.unwrap_or_default(),
60 enable_hnsw: self.enable_hnsw.unwrap_or_default(),
61 })
62 }
63 fn create_empty() -> Self {
65 Self {
66 lookup: core::default::Default::default(),
67 range: core::default::Default::default(),
68 is_principal: core::default::Default::default(),
69 on_disk: core::default::Default::default(),
70 enable_hnsw: core::default::Default::default(),
71 }
72 }
73}
74
75impl From<IntegerIndexParamsBuilder> for IntegerIndexParams {
76 fn from(value: IntegerIndexParamsBuilder) -> Self {
77 value.build_inner().unwrap_or_else(|_| {
78 panic!(
79 "Failed to convert {0} to {1}",
80 "IntegerIndexParamsBuilder", "IntegerIndexParams"
81 )
82 })
83 }
84}
85
86impl IntegerIndexParamsBuilder {
87 pub fn build(self) -> IntegerIndexParams {
89 self.build_inner().unwrap_or_else(|_| {
90 panic!(
91 "Failed to build {0} into {1}",
92 "IntegerIndexParamsBuilder", "IntegerIndexParams"
93 )
94 })
95 }
96}
97
98impl Default for IntegerIndexParamsBuilder {
99 fn default() -> Self {
100 Self::create_empty()
101 }
102}
103
104#[non_exhaustive]
106#[derive(Debug)]
107pub enum IntegerIndexParamsBuilderError {
108 UninitializedField(&'static str),
110 ValidationError(String),
112}
113
114impl std::fmt::Display for IntegerIndexParamsBuilderError {
116 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
117 match self {
118 Self::UninitializedField(field) => {
119 write!(f, "`{field}` must be initialized")
120 }
121 Self::ValidationError(error) => write!(f, "{error}"),
122 }
123 }
124}
125
126impl std::error::Error for IntegerIndexParamsBuilderError {}
128
129impl From<derive_builder::UninitializedFieldError> for IntegerIndexParamsBuilderError {
131 fn from(error: derive_builder::UninitializedFieldError) -> Self {
132 Self::UninitializedField(error.field_name())
133 }
134}
135
136impl From<String> for IntegerIndexParamsBuilderError {
138 fn from(error: String) -> Self {
139 Self::ValidationError(error)
140 }
141}