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