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}
14
15impl IntegerIndexParamsBuilder {
16 pub fn new(lookup: bool, range: bool) -> Self {
17 Self::create_empty().lookup(lookup).range(range)
18 }
19
20 pub fn lookup<VALUE: core::convert::Into<bool>>(self, value: VALUE) -> Self {
22 let mut new = self;
23 new.lookup = Option::Some(Option::Some(value.into()));
24 new
25 }
26 pub fn range<VALUE: core::convert::Into<bool>>(self, value: VALUE) -> Self {
28 let mut new = self;
29 new.range = Option::Some(Option::Some(value.into()));
30 new
31 }
32 pub fn is_principal(self, value: bool) -> Self {
34 let mut new = self;
35 new.is_principal = Option::Some(Option::Some(value));
36 new
37 }
38 pub fn on_disk(self, value: bool) -> Self {
40 let mut new = self;
41 new.on_disk = Option::Some(Option::Some(value));
42 new
43 }
44
45 fn build_inner(self) -> Result<IntegerIndexParams, IntegerIndexParamsBuilderError> {
46 Ok(IntegerIndexParams {
47 lookup: self.lookup.unwrap_or_default(),
48 range: self.range.unwrap_or_default(),
49 is_principal: self.is_principal.unwrap_or_default(),
50 on_disk: self.on_disk.unwrap_or_default(),
51 })
52 }
53 fn create_empty() -> Self {
55 Self {
56 lookup: core::default::Default::default(),
57 range: core::default::Default::default(),
58 is_principal: core::default::Default::default(),
59 on_disk: core::default::Default::default(),
60 }
61 }
62}
63
64impl From<IntegerIndexParamsBuilder> for IntegerIndexParams {
65 fn from(value: IntegerIndexParamsBuilder) -> Self {
66 value.build_inner().unwrap_or_else(|_| {
67 panic!(
68 "Failed to convert {0} to {1}",
69 "IntegerIndexParamsBuilder", "IntegerIndexParams"
70 )
71 })
72 }
73}
74
75impl IntegerIndexParamsBuilder {
76 pub fn build(self) -> IntegerIndexParams {
78 self.build_inner().unwrap_or_else(|_| {
79 panic!(
80 "Failed to build {0} into {1}",
81 "IntegerIndexParamsBuilder", "IntegerIndexParams"
82 )
83 })
84 }
85}
86
87impl Default for IntegerIndexParamsBuilder {
88 fn default() -> Self {
89 Self::create_empty()
90 }
91}
92
93#[non_exhaustive]
95#[derive(Debug)]
96pub enum IntegerIndexParamsBuilderError {
97 UninitializedField(&'static str),
99 ValidationError(String),
101}
102
103impl std::fmt::Display for IntegerIndexParamsBuilderError {
105 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
106 match self {
107 Self::UninitializedField(field) => {
108 write!(f, "`{field}` must be initialized")
109 }
110 Self::ValidationError(error) => write!(f, "{error}"),
111 }
112 }
113}
114
115impl std::error::Error for IntegerIndexParamsBuilderError {}
117
118impl From<derive_builder::UninitializedFieldError> for IntegerIndexParamsBuilderError {
120 fn from(error: derive_builder::UninitializedFieldError) -> Self {
121 Self::UninitializedField(error.field_name())
122 }
123}
124
125impl From<String> for IntegerIndexParamsBuilderError {
127 fn from(error: String) -> Self {
128 Self::ValidationError(error)
129 }
130}