qdrant_client/builders/
create_shard_key_builder.rs1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct CreateShardKeyBuilder {
5 pub(crate) shard_key: Option<Option<ShardKey>>,
7 pub(crate) shards_number: Option<Option<u32>>,
9 pub(crate) replication_factor: Option<Option<u32>>,
11 pub(crate) placement: Option<Vec<u64>>,
13 pub(crate) initial_state: Option<Option<i32>>,
19}
20
21impl CreateShardKeyBuilder {
22 pub fn shard_key<VALUE: core::convert::Into<ShardKey>>(self, value: VALUE) -> Self {
24 let mut new = self;
25 new.shard_key = Option::Some(Option::Some(value.into()));
26 new
27 }
28 pub fn shards_number(self, value: u32) -> Self {
30 let mut new = self;
31 new.shards_number = Option::Some(Option::Some(value));
32 new
33 }
34 pub fn replication_factor(self, value: u32) -> Self {
36 let mut new = self;
37 new.replication_factor = Option::Some(Option::Some(value));
38 new
39 }
40 pub fn placement(self, value: Vec<u64>) -> Self {
42 let mut new = self;
43 new.placement = Option::Some(value);
44 new
45 }
46 #[allow(unused_mut)]
54 pub fn initial_state(self, value: ReplicaState) -> Self {
55 let mut new = self;
56 new.initial_state = Option::Some(Option::Some(value as i32));
57 new
58 }
59
60 fn build_inner(self) -> Result<CreateShardKey, std::convert::Infallible> {
61 Ok(CreateShardKey {
62 shard_key: self.shard_key.unwrap_or_default(),
63 shards_number: self.shards_number.unwrap_or_default(),
64 replication_factor: self.replication_factor.unwrap_or_default(),
65 placement: self.placement.unwrap_or_default(),
66 initial_state: self.initial_state.unwrap_or_default(),
67 })
68 }
69 fn create_empty() -> Self {
71 Self {
72 shard_key: core::default::Default::default(),
73 shards_number: core::default::Default::default(),
74 replication_factor: core::default::Default::default(),
75 placement: core::default::Default::default(),
76 initial_state: core::default::Default::default(),
77 }
78 }
79}
80
81impl From<CreateShardKeyBuilder> for CreateShardKey {
82 fn from(value: CreateShardKeyBuilder) -> Self {
83 value.build_inner().unwrap_or_else(|_| {
84 panic!(
85 "Failed to convert {0} to {1}",
86 "CreateShardKeyBuilder", "CreateShardKey"
87 )
88 })
89 }
90}
91
92impl CreateShardKeyBuilder {
93 pub fn build(self) -> CreateShardKey {
95 self.build_inner().unwrap_or_else(|_| {
96 panic!(
97 "Failed to build {0} into {1}",
98 "CreateShardKeyBuilder", "CreateShardKey"
99 )
100 })
101 }
102}
103
104impl Default for CreateShardKeyBuilder {
105 fn default() -> Self {
106 Self::create_empty()
107 }
108}