Skip to main content

qdrant_client/builders/
abort_shard_transfer_builder.rs

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