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