qdrant_client/builders/
replica_builder.rs1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct ReplicaBuilder {
5 pub(crate) shard_id: Option<u32>,
6 pub(crate) peer_id: Option<u64>,
7}
8
9impl ReplicaBuilder {
10 #[allow(unused_mut)]
11 pub fn shard_id(self, value: u32) -> Self {
12 let mut new = self;
13 new.shard_id = Option::Some(value);
14 new
15 }
16 #[allow(unused_mut)]
17 pub fn peer_id(self, value: u64) -> Self {
18 let mut new = self;
19 new.peer_id = Option::Some(value);
20 new
21 }
22
23 fn build_inner(self) -> Result<Replica, ReplicaBuilderError> {
24 Ok(Replica {
25 shard_id: match self.shard_id {
26 Some(value) => value,
27 None => {
28 return Result::Err(core::convert::Into::into(
29 ::derive_builder::UninitializedFieldError::from("shard_id"),
30 ));
31 }
32 },
33 peer_id: match self.peer_id {
34 Some(value) => value,
35 None => {
36 return Result::Err(core::convert::Into::into(
37 ::derive_builder::UninitializedFieldError::from("peer_id"),
38 ));
39 }
40 },
41 })
42 }
43 fn create_empty() -> Self {
45 Self {
46 shard_id: core::default::Default::default(),
47 peer_id: core::default::Default::default(),
48 }
49 }
50}
51
52impl From<ReplicaBuilder> for Replica {
53 fn from(value: ReplicaBuilder) -> Self {
54 value
55 .build_inner()
56 .unwrap_or_else(|_| panic!("Failed to convert {0} to {1}", "ReplicaBuilder", "Replica"))
57 }
58}
59
60impl ReplicaBuilder {
61 pub fn build(self) -> Replica {
63 self.build_inner()
64 .unwrap_or_else(|_| panic!("Failed to build {0} into {1}", "ReplicaBuilder", "Replica"))
65 }
66}
67
68impl ReplicaBuilder {
69 pub(crate) fn empty() -> Self {
70 Self::create_empty()
71 }
72}
73
74#[non_exhaustive]
76#[derive(Debug)]
77pub enum ReplicaBuilderError {
78 UninitializedField(&'static str),
80 ValidationError(String),
82}
83
84impl std::fmt::Display for ReplicaBuilderError {
86 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
87 match self {
88 Self::UninitializedField(field) => {
89 write!(f, "`{field}` must be initialized")
90 }
91 Self::ValidationError(error) => write!(f, "{error}"),
92 }
93 }
94}
95
96impl std::error::Error for ReplicaBuilderError {}
98
99impl From<derive_builder::UninitializedFieldError> for ReplicaBuilderError {
101 fn from(error: derive_builder::UninitializedFieldError) -> Self {
102 Self::UninitializedField(error.field_name())
103 }
104}
105
106impl From<String> for ReplicaBuilderError {
108 fn from(error: String) -> Self {
109 Self::ValidationError(error)
110 }
111}