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