qdrant_client/builders/
create_field_index_collection_builder.rs1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[must_use]
5#[derive(Clone)]
6pub struct CreateFieldIndexCollectionBuilder {
7 pub(crate) collection_name: Option<String>,
9 pub(crate) wait: Option<Option<bool>>,
11 pub(crate) field_name: Option<String>,
13 pub(crate) field_type: Option<Option<i32>>,
15 field_index_params: Option<payload_index_params::IndexParams>,
17 pub(crate) ordering: Option<Option<WriteOrdering>>,
19 pub(crate) timeout: Option<Option<u64>>,
21}
22
23impl CreateFieldIndexCollectionBuilder {
24 pub fn collection_name(self, value: String) -> Self {
26 let mut new = self;
27 new.collection_name = Option::Some(value);
28 new
29 }
30 pub fn wait(self, value: bool) -> Self {
32 let mut new = self;
33 new.wait = Option::Some(Option::Some(value));
34 new
35 }
36 pub fn field_name(self, value: String) -> Self {
38 let mut new = self;
39 new.field_name = Option::Some(value);
40 new
41 }
42 pub fn field_type<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
44 let mut new = self;
45 new.field_type = Option::Some(Option::Some(value.into()));
46 new
47 }
48 pub fn field_index_params<VALUE: core::convert::Into<payload_index_params::IndexParams>>(
50 self,
51 value: VALUE,
52 ) -> Self {
53 let mut new = self;
54 new.field_index_params = Option::Some(value.into());
55 new
56 }
57 pub fn ordering<VALUE: core::convert::Into<WriteOrdering>>(self, value: VALUE) -> Self {
59 let mut new = self;
60 new.ordering = Option::Some(Option::Some(value.into()));
61 new
62 }
63 pub fn timeout(self, value: u64) -> Self {
65 let mut new = self;
66 new.timeout = Option::Some(Option::Some(value));
67 new
68 }
69
70 fn build_inner(
71 self,
72 ) -> Result<CreateFieldIndexCollection, CreateFieldIndexCollectionBuilderError> {
73 Ok(CreateFieldIndexCollection {
74 collection_name: match self.collection_name {
75 Some(value) => value,
76 None => {
77 return Result::Err(core::convert::Into::into(
78 ::derive_builder::UninitializedFieldError::from("collection_name"),
79 ));
80 }
81 },
82 wait: self.wait.unwrap_or_default(),
83 field_name: match self.field_name {
84 Some(value) => value,
85 None => {
86 return Result::Err(core::convert::Into::into(
87 ::derive_builder::UninitializedFieldError::from("field_name"),
88 ));
89 }
90 },
91 field_type: self.field_type.unwrap_or_default(),
92 field_index_params: { convert_option(&self.field_index_params) },
93 ordering: self.ordering.unwrap_or_default(),
94 timeout: self.timeout.unwrap_or_default(),
95 })
96 }
97 fn create_empty() -> Self {
99 Self {
100 collection_name: core::default::Default::default(),
101 wait: core::default::Default::default(),
102 field_name: core::default::Default::default(),
103 field_type: core::default::Default::default(),
104 field_index_params: core::default::Default::default(),
105 ordering: core::default::Default::default(),
106 timeout: core::default::Default::default(),
107 }
108 }
109}
110
111impl From<CreateFieldIndexCollectionBuilder> for CreateFieldIndexCollection {
112 fn from(value: CreateFieldIndexCollectionBuilder) -> Self {
113 value.build_inner().unwrap_or_else(|_| {
114 panic!(
115 "Failed to convert {0} to {1}",
116 "CreateFieldIndexCollectionBuilder", "CreateFieldIndexCollection"
117 )
118 })
119 }
120}
121
122impl CreateFieldIndexCollectionBuilder {
123 pub fn build(self) -> CreateFieldIndexCollection {
125 self.build_inner().unwrap_or_else(|_| {
126 panic!(
127 "Failed to build {0} into {1}",
128 "CreateFieldIndexCollectionBuilder", "CreateFieldIndexCollection"
129 )
130 })
131 }
132}
133
134impl CreateFieldIndexCollectionBuilder {
135 pub(crate) fn empty() -> Self {
136 Self::create_empty()
137 }
138}
139
140#[non_exhaustive]
142#[derive(Debug)]
143pub enum CreateFieldIndexCollectionBuilderError {
144 UninitializedField(&'static str),
146 ValidationError(String),
148}
149
150impl std::fmt::Display for CreateFieldIndexCollectionBuilderError {
152 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
153 match self {
154 Self::UninitializedField(field) => {
155 write!(f, "`{field}` must be initialized")
156 }
157 Self::ValidationError(error) => write!(f, "{error}"),
158 }
159 }
160}
161
162impl std::error::Error for CreateFieldIndexCollectionBuilderError {}
164
165impl From<derive_builder::UninitializedFieldError> for CreateFieldIndexCollectionBuilderError {
167 fn from(error: derive_builder::UninitializedFieldError) -> Self {
168 Self::UninitializedField(error.field_name())
169 }
170}
171
172impl From<String> for CreateFieldIndexCollectionBuilderError {
174 fn from(error: String) -> Self {
175 Self::ValidationError(error)
176 }
177}