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 pub(crate) memory: Option<Option<i32>>,
18}
19
20impl IntegerIndexParamsBuilder {
21 pub fn new(lookup: bool, range: bool) -> Self {
22 Self::create_empty().lookup(lookup).range(range)
23 }
24
25 pub fn lookup<VALUE: core::convert::Into<bool>>(self, value: VALUE) -> Self {
27 let mut new = self;
28 new.lookup = Option::Some(Option::Some(value.into()));
29 new
30 }
31 pub fn range<VALUE: core::convert::Into<bool>>(self, value: VALUE) -> Self {
33 let mut new = self;
34 new.range = Option::Some(Option::Some(value.into()));
35 new
36 }
37 pub fn is_principal(self, value: bool) -> Self {
39 let mut new = self;
40 new.is_principal = Option::Some(Option::Some(value));
41 new
42 }
43 pub fn on_disk(self, value: bool) -> Self {
47 let mut new = self;
48 new.on_disk = Option::Some(Option::Some(value));
49 new
50 }
51 pub fn enable_hnsw(self, value: bool) -> Self {
53 let mut new = self;
54 new.enable_hnsw = Option::Some(Option::Some(value));
55 new
56 }
57 pub fn memory<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
60 let mut new = self;
61 new.memory = Option::Some(Option::Some(value.into()));
62 new
63 }
64
65 #[allow(deprecated)]
66 fn build_inner(self) -> Result<IntegerIndexParams, IntegerIndexParamsBuilderError> {
67 Ok(IntegerIndexParams {
68 lookup: self.lookup.unwrap_or_default(),
69 range: self.range.unwrap_or_default(),
70 is_principal: self.is_principal.unwrap_or_default(),
71 on_disk: self.on_disk.unwrap_or_default(),
72 enable_hnsw: self.enable_hnsw.unwrap_or_default(),
73 memory: self.memory.unwrap_or_default(),
74 })
75 }
76 fn create_empty() -> Self {
78 Self {
79 lookup: core::default::Default::default(),
80 range: core::default::Default::default(),
81 is_principal: core::default::Default::default(),
82 on_disk: core::default::Default::default(),
83 enable_hnsw: core::default::Default::default(),
84 memory: core::default::Default::default(),
85 }
86 }
87}
88
89impl From<IntegerIndexParamsBuilder> for IntegerIndexParams {
90 fn from(value: IntegerIndexParamsBuilder) -> Self {
91 value.build_inner().unwrap_or_else(|_| {
92 panic!(
93 "Failed to convert {0} to {1}",
94 "IntegerIndexParamsBuilder", "IntegerIndexParams"
95 )
96 })
97 }
98}
99
100impl IntegerIndexParamsBuilder {
101 pub fn build(self) -> IntegerIndexParams {
103 self.build_inner().unwrap_or_else(|_| {
104 panic!(
105 "Failed to build {0} into {1}",
106 "IntegerIndexParamsBuilder", "IntegerIndexParams"
107 )
108 })
109 }
110}
111
112impl Default for IntegerIndexParamsBuilder {
113 fn default() -> Self {
114 Self::create_empty()
115 }
116}
117
118#[non_exhaustive]
120#[derive(Debug)]
121pub enum IntegerIndexParamsBuilderError {
122 UninitializedField(&'static str),
124 ValidationError(String),
126}
127
128impl std::fmt::Display for IntegerIndexParamsBuilderError {
130 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
131 match self {
132 Self::UninitializedField(field) => {
133 write!(f, "`{field}` must be initialized")
134 }
135 Self::ValidationError(error) => write!(f, "{error}"),
136 }
137 }
138}
139
140impl std::error::Error for IntegerIndexParamsBuilderError {}
142
143impl From<derive_builder::UninitializedFieldError> for IntegerIndexParamsBuilderError {
145 fn from(error: derive_builder::UninitializedFieldError) -> Self {
146 Self::UninitializedField(error.field_name())
147 }
148}
149
150impl From<String> for IntegerIndexParamsBuilderError {
152 fn from(error: String) -> Self {
153 Self::ValidationError(error)
154 }
155}