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