qdrant_client/builders/
create_field_index_collection_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct CreateFieldIndexCollectionBuilder {
6    /// name of the collection
7    pub(crate) collection_name: Option<String>,
8    /// Wait until the changes have been applied?
9    pub(crate) wait: Option<Option<bool>>,
10    /// Field name to index
11    pub(crate) field_name: Option<String>,
12    /// Field type.
13    pub(crate) field_type: Option<Option<i32>>,
14    /// Payload index params.
15    field_index_params: Option<payload_index_params::IndexParams>,
16    /// Write ordering guarantees
17    pub(crate) ordering: Option<Option<WriteOrdering>>,
18}
19
20impl CreateFieldIndexCollectionBuilder {
21    /// name of the collection
22    #[allow(unused_mut)]
23    pub fn collection_name(self, value: String) -> Self {
24        let mut new = self;
25        new.collection_name = Option::Some(value);
26        new
27    }
28    /// Wait until the changes have been applied?
29    #[allow(unused_mut)]
30    pub fn wait(self, value: bool) -> Self {
31        let mut new = self;
32        new.wait = Option::Some(Option::Some(value));
33        new
34    }
35    /// Field name to index
36    #[allow(unused_mut)]
37    pub fn field_name(self, value: String) -> Self {
38        let mut new = self;
39        new.field_name = Option::Some(value);
40        new
41    }
42    /// Field type.
43    #[allow(unused_mut)]
44    pub fn field_type<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
45        let mut new = self;
46        new.field_type = Option::Some(Option::Some(value.into()));
47        new
48    }
49    /// Payload index params.
50    #[allow(unused_mut)]
51    pub fn field_index_params<VALUE: core::convert::Into<payload_index_params::IndexParams>>(
52        self,
53        value: VALUE,
54    ) -> Self {
55        let mut new = self;
56        new.field_index_params = Option::Some(value.into());
57        new
58    }
59    /// Write ordering guarantees
60    #[allow(unused_mut)]
61    pub fn ordering<VALUE: core::convert::Into<WriteOrdering>>(self, value: VALUE) -> Self {
62        let mut new = self;
63        new.ordering = Option::Some(Option::Some(value.into()));
64        new
65    }
66
67    fn build_inner(
68        self,
69    ) -> Result<CreateFieldIndexCollection, CreateFieldIndexCollectionBuilderError> {
70        Ok(CreateFieldIndexCollection {
71            collection_name: match self.collection_name {
72                Some(value) => value,
73                None => {
74                    return Result::Err(core::convert::Into::into(
75                        ::derive_builder::UninitializedFieldError::from("collection_name"),
76                    ));
77                }
78            },
79            wait: self.wait.unwrap_or_default(),
80            field_name: match self.field_name {
81                Some(value) => value,
82                None => {
83                    return Result::Err(core::convert::Into::into(
84                        ::derive_builder::UninitializedFieldError::from("field_name"),
85                    ));
86                }
87            },
88            field_type: self.field_type.unwrap_or_default(),
89            field_index_params: { convert_option(&self.field_index_params) },
90            ordering: self.ordering.unwrap_or_default(),
91        })
92    }
93    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
94    fn create_empty() -> Self {
95        Self {
96            collection_name: core::default::Default::default(),
97            wait: core::default::Default::default(),
98            field_name: core::default::Default::default(),
99            field_type: core::default::Default::default(),
100            field_index_params: core::default::Default::default(),
101            ordering: core::default::Default::default(),
102        }
103    }
104}
105
106impl From<CreateFieldIndexCollectionBuilder> for CreateFieldIndexCollection {
107    fn from(value: CreateFieldIndexCollectionBuilder) -> Self {
108        value.build_inner().unwrap_or_else(|_| {
109            panic!(
110                "Failed to convert {0} to {1}",
111                "CreateFieldIndexCollectionBuilder", "CreateFieldIndexCollection"
112            )
113        })
114    }
115}
116
117impl CreateFieldIndexCollectionBuilder {
118    /// Builds the desired type. Can often be omitted.
119    pub fn build(self) -> CreateFieldIndexCollection {
120        self.build_inner().unwrap_or_else(|_| {
121            panic!(
122                "Failed to build {0} into {1}",
123                "CreateFieldIndexCollectionBuilder", "CreateFieldIndexCollection"
124            )
125        })
126    }
127}
128
129impl CreateFieldIndexCollectionBuilder {
130    pub(crate) fn empty() -> Self {
131        Self::create_empty()
132    }
133}
134
135/// Error type for CreateFieldIndexCollectionBuilder
136#[non_exhaustive]
137#[derive(Debug)]
138pub enum CreateFieldIndexCollectionBuilderError {
139    /// Uninitialized field
140    UninitializedField(&'static str),
141    /// Custom validation error
142    ValidationError(String),
143}
144
145// Implementing the Display trait for better error messages
146impl std::fmt::Display for CreateFieldIndexCollectionBuilderError {
147    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
148        match self {
149            Self::UninitializedField(field) => {
150                write!(f, "`{field}` must be initialized")
151            }
152            Self::ValidationError(error) => write!(f, "{error}"),
153        }
154    }
155}
156
157// Implementing the Error trait
158impl std::error::Error for CreateFieldIndexCollectionBuilderError {}
159
160// Implementing From trait for conversion from UninitializedFieldError
161impl From<derive_builder::UninitializedFieldError> for CreateFieldIndexCollectionBuilderError {
162    fn from(error: derive_builder::UninitializedFieldError) -> Self {
163        Self::UninitializedField(error.field_name())
164    }
165}
166
167// Implementing From trait for conversion from String
168impl From<String> for CreateFieldIndexCollectionBuilderError {
169    fn from(error: String) -> Self {
170        Self::ValidationError(error)
171    }
172}