Skip to main content

qdrant_client/builders/
delete_field_index_collection_builder.rs

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