qdrant_client/builders/
scalar_quantization_builder.rs1use crate::qdrant::*;
2
3#[must_use]
4#[derive(Clone)]
5pub struct ScalarQuantizationBuilder {
6 pub(crate) r#type: Option<i32>,
8 pub(crate) quantile: Option<Option<f32>>,
10 pub(crate) always_ram: Option<Option<bool>>,
12 pub(crate) memory: Option<Option<i32>>,
14}
15
16impl ScalarQuantizationBuilder {
17 pub fn r#type(self, value: i32) -> Self {
19 let mut new = self;
20 new.r#type = Option::Some(value);
21 new
22 }
23 pub fn quantile(self, value: f32) -> Self {
25 let mut new = self;
26 new.quantile = Option::Some(Option::Some(value));
27 new
28 }
29 pub fn always_ram(self, value: bool) -> Self {
33 let mut new = self;
34 new.always_ram = Option::Some(Option::Some(value));
35 new
36 }
37 pub fn memory<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
40 let mut new = self;
41 new.memory = Option::Some(Option::Some(value.into()));
42 new
43 }
44
45 #[allow(deprecated)]
46 fn build_inner(self) -> Result<ScalarQuantization, ScalarQuantizationBuilderError> {
47 Ok(ScalarQuantization {
48 r#type: match self.r#type {
49 Some(value) => value,
50 None => {
51 return Result::Err(core::convert::Into::into(
52 ::derive_builder::UninitializedFieldError::from("r#type"),
53 ));
54 }
55 },
56 quantile: self.quantile.unwrap_or_default(),
57 always_ram: self.always_ram.unwrap_or_default(),
58 memory: self.memory.unwrap_or_default(),
59 })
60 }
61 fn create_empty() -> Self {
63 Self {
64 r#type: core::default::Default::default(),
65 quantile: core::default::Default::default(),
66 always_ram: core::default::Default::default(),
67 memory: core::default::Default::default(),
68 }
69 }
70}
71
72impl From<ScalarQuantizationBuilder> for ScalarQuantization {
73 fn from(value: ScalarQuantizationBuilder) -> Self {
74 value.build_inner().unwrap_or_else(|_| {
75 panic!(
76 "Failed to convert {0} to {1}",
77 "ScalarQuantizationBuilder", "ScalarQuantization"
78 )
79 })
80 }
81}
82
83impl ScalarQuantizationBuilder {
84 pub fn build(self) -> ScalarQuantization {
86 self.build_inner().unwrap_or_else(|_| {
87 panic!(
88 "Failed to build {0} into {1}",
89 "ScalarQuantizationBuilder", "ScalarQuantization"
90 )
91 })
92 }
93}
94
95impl ScalarQuantizationBuilder {
96 pub(crate) fn empty() -> Self {
97 Self::create_empty()
98 }
99}
100
101#[non_exhaustive]
102#[derive(Debug)]
103pub enum ScalarQuantizationBuilderError {
104 UninitializedField(&'static str),
106 ValidationError(String),
108}
109
110impl std::fmt::Display for ScalarQuantizationBuilderError {
112 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
113 match self {
114 Self::UninitializedField(field) => {
115 write!(f, "`{field}` must be initialized")
116 }
117 Self::ValidationError(error) => write!(f, "{error}"),
118 }
119 }
120}
121
122impl std::error::Error for ScalarQuantizationBuilderError {}
124
125impl From<derive_builder::UninitializedFieldError> for ScalarQuantizationBuilderError {
127 fn from(error: derive_builder::UninitializedFieldError) -> Self {
128 Self::UninitializedField(error.field_name())
129 }
130}
131
132impl From<String> for ScalarQuantizationBuilderError {
134 fn from(error: String) -> Self {
135 Self::ValidationError(error)
136 }
137}