Skip to main content

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    /// Timeout for the request in seconds
19    pub(crate) timeout: Option<Option<u64>>,
20}
21
22impl CreateFieldIndexCollectionBuilder {
23    /// name of the collection
24    pub fn collection_name(self, value: String) -> Self {
25        let mut new = self;
26        new.collection_name = Option::Some(value);
27        new
28    }
29    /// Wait until the changes have been applied?
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    pub fn field_name(self, value: String) -> Self {
37        let mut new = self;
38        new.field_name = Option::Some(value);
39        new
40    }
41    /// Field type.
42    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    /// Payload index params.
48    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    /// Write ordering guarantees
57    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    /// Timeout for the request in seconds
63    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    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
97    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    /// Builds the desired type. Can often be omitted.
123    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/// Error type for CreateFieldIndexCollectionBuilder
140#[non_exhaustive]
141#[derive(Debug)]
142pub enum CreateFieldIndexCollectionBuilderError {
143    /// Uninitialized field
144    UninitializedField(&'static str),
145    /// Custom validation error
146    ValidationError(String),
147}
148
149// Implementing the Display trait for better error messages
150impl 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
161// Implementing the Error trait
162impl std::error::Error for CreateFieldIndexCollectionBuilderError {}
163
164// Implementing From trait for conversion from UninitializedFieldError
165impl From<derive_builder::UninitializedFieldError> for CreateFieldIndexCollectionBuilderError {
166    fn from(error: derive_builder::UninitializedFieldError) -> Self {
167        Self::UninitializedField(error.field_name())
168    }
169}
170
171// Implementing From trait for conversion from String
172impl From<String> for CreateFieldIndexCollectionBuilderError {
173    fn from(error: String) -> Self {
174        Self::ValidationError(error)
175    }
176}