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}
19
20impl CreateFieldIndexCollectionBuilder {
21 pub fn collection_name(self, value: String) -> Self {
23 let mut new = self;
24 new.collection_name = Option::Some(value);
25 new
26 }
27 pub fn wait(self, value: bool) -> Self {
29 let mut new = self;
30 new.wait = Option::Some(Option::Some(value));
31 new
32 }
33 pub fn field_name(self, value: String) -> Self {
35 let mut new = self;
36 new.field_name = Option::Some(value);
37 new
38 }
39 pub fn field_type<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
41 let mut new = self;
42 new.field_type = Option::Some(Option::Some(value.into()));
43 new
44 }
45 pub fn field_index_params<VALUE: core::convert::Into<payload_index_params::IndexParams>>(
47 self,
48 value: VALUE,
49 ) -> Self {
50 let mut new = self;
51 new.field_index_params = Option::Some(value.into());
52 new
53 }
54 pub fn ordering<VALUE: core::convert::Into<WriteOrdering>>(self, value: VALUE) -> Self {
56 let mut new = self;
57 new.ordering = Option::Some(Option::Some(value.into()));
58 new
59 }
60
61 fn build_inner(
62 self,
63 ) -> Result<CreateFieldIndexCollection, CreateFieldIndexCollectionBuilderError> {
64 Ok(CreateFieldIndexCollection {
65 collection_name: match self.collection_name {
66 Some(value) => value,
67 None => {
68 return Result::Err(core::convert::Into::into(
69 ::derive_builder::UninitializedFieldError::from("collection_name"),
70 ));
71 }
72 },
73 wait: self.wait.unwrap_or_default(),
74 field_name: match self.field_name {
75 Some(value) => value,
76 None => {
77 return Result::Err(core::convert::Into::into(
78 ::derive_builder::UninitializedFieldError::from("field_name"),
79 ));
80 }
81 },
82 field_type: self.field_type.unwrap_or_default(),
83 field_index_params: { convert_option(&self.field_index_params) },
84 ordering: self.ordering.unwrap_or_default(),
85 })
86 }
87 fn create_empty() -> Self {
89 Self {
90 collection_name: core::default::Default::default(),
91 wait: core::default::Default::default(),
92 field_name: core::default::Default::default(),
93 field_type: core::default::Default::default(),
94 field_index_params: core::default::Default::default(),
95 ordering: core::default::Default::default(),
96 }
97 }
98}
99
100impl From<CreateFieldIndexCollectionBuilder> for CreateFieldIndexCollection {
101 fn from(value: CreateFieldIndexCollectionBuilder) -> Self {
102 value.build_inner().unwrap_or_else(|_| {
103 panic!(
104 "Failed to convert {0} to {1}",
105 "CreateFieldIndexCollectionBuilder", "CreateFieldIndexCollection"
106 )
107 })
108 }
109}
110
111impl CreateFieldIndexCollectionBuilder {
112 pub fn build(self) -> CreateFieldIndexCollection {
114 self.build_inner().unwrap_or_else(|_| {
115 panic!(
116 "Failed to build {0} into {1}",
117 "CreateFieldIndexCollectionBuilder", "CreateFieldIndexCollection"
118 )
119 })
120 }
121}
122
123impl CreateFieldIndexCollectionBuilder {
124 pub(crate) fn empty() -> Self {
125 Self::create_empty()
126 }
127}
128
129#[non_exhaustive]
131#[derive(Debug)]
132pub enum CreateFieldIndexCollectionBuilderError {
133 UninitializedField(&'static str),
135 ValidationError(String),
137}
138
139impl std::fmt::Display for CreateFieldIndexCollectionBuilderError {
141 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
142 match self {
143 Self::UninitializedField(field) => {
144 write!(f, "`{field}` must be initialized")
145 }
146 Self::ValidationError(error) => write!(f, "{error}"),
147 }
148 }
149}
150
151impl std::error::Error for CreateFieldIndexCollectionBuilderError {}
153
154impl From<derive_builder::UninitializedFieldError> for CreateFieldIndexCollectionBuilderError {
156 fn from(error: derive_builder::UninitializedFieldError) -> Self {
157 Self::UninitializedField(error.field_name())
158 }
159}
160
161impl From<String> for CreateFieldIndexCollectionBuilderError {
163 fn from(error: String) -> Self {
164 Self::ValidationError(error)
165 }
166}