Skip to main content

qdrant_client/builders/
create_shard_key_request_builder.rs

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