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