qdrant_client/builders/
replicate_shard_builder.rs

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