Skip to main content

qdrant_client/builders/
delete_field_index_collection_builder.rs

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