qdrant_client/builders/
delete_collection_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct DeleteCollectionBuilder {
5    /// Name of the collection
6    pub(crate) collection_name: Option<String>,
7    /// Wait timeout for operation commit in seconds, if not specified - default value will be supplied
8    pub(crate) timeout: Option<Option<u64>>,
9}
10
11impl DeleteCollectionBuilder {
12    /// Name of the collection
13    pub fn collection_name(self, value: String) -> Self {
14        let mut new = self;
15        new.collection_name = Option::Some(value);
16        new
17    }
18    /// Wait timeout for operation commit in seconds, if not specified - default value will be supplied
19    pub fn timeout(self, value: u64) -> Self {
20        let mut new = self;
21        new.timeout = Option::Some(Option::Some(value));
22        new
23    }
24
25    fn build_inner(self) -> Result<DeleteCollection, DeleteCollectionBuilderError> {
26        Ok(DeleteCollection {
27            collection_name: match self.collection_name {
28                Some(value) => value,
29                None => {
30                    return Result::Err(core::convert::Into::into(
31                        ::derive_builder::UninitializedFieldError::from("collection_name"),
32                    ));
33                }
34            },
35            timeout: self.timeout.unwrap_or_default(),
36        })
37    }
38    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
39    fn create_empty() -> Self {
40        Self {
41            collection_name: core::default::Default::default(),
42            timeout: core::default::Default::default(),
43        }
44    }
45}
46
47impl From<DeleteCollectionBuilder> for DeleteCollection {
48    fn from(value: DeleteCollectionBuilder) -> Self {
49        value.build_inner().unwrap_or_else(|_| {
50            panic!(
51                "Failed to convert {0} to {1}",
52                "DeleteCollectionBuilder", "DeleteCollection"
53            )
54        })
55    }
56}
57
58impl DeleteCollectionBuilder {
59    /// Builds the desired type. Can often be omitted.
60    pub fn build(self) -> DeleteCollection {
61        self.build_inner().unwrap_or_else(|_| {
62            panic!(
63                "Failed to build {0} into {1}",
64                "DeleteCollectionBuilder", "DeleteCollection"
65            )
66        })
67    }
68}
69
70impl DeleteCollectionBuilder {
71    pub(crate) fn empty() -> Self {
72        Self::create_empty()
73    }
74}
75
76/// Error type for DeleteCollectionBuilder
77#[non_exhaustive]
78#[derive(Debug)]
79pub enum DeleteCollectionBuilderError {
80    /// Uninitialized field
81    UninitializedField(&'static str),
82    /// Custom validation error
83    ValidationError(String),
84}
85
86// Implementing the Display trait for better error messages
87impl std::fmt::Display for DeleteCollectionBuilderError {
88    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
89        match self {
90            Self::UninitializedField(field) => {
91                write!(f, "`{field}` must be initialized")
92            }
93            Self::ValidationError(error) => write!(f, "{error}"),
94        }
95    }
96}
97
98// Implementing the Error trait
99impl std::error::Error for DeleteCollectionBuilderError {}
100
101// Implementing From trait for conversion from UninitializedFieldError
102impl From<derive_builder::UninitializedFieldError> for DeleteCollectionBuilderError {
103    fn from(error: derive_builder::UninitializedFieldError) -> Self {
104        Self::UninitializedField(error.field_name())
105    }
106}
107
108// Implementing From trait for conversion from String
109impl From<String> for DeleteCollectionBuilderError {
110    fn from(error: String) -> Self {
111        Self::ValidationError(error)
112    }
113}