qdrant_client/builders/
create_shard_key_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct CreateShardKeyBuilder {
5    /// User-defined shard key
6    pub(crate) shard_key: Option<Option<ShardKey>>,
7    /// Number of shards to create per shard key
8    pub(crate) shards_number: Option<Option<u32>>,
9    /// Number of replicas of each shard to create
10    pub(crate) replication_factor: Option<Option<u32>>,
11    /// List of peer ids, allowed to create shards. If empty - all peers are allowed
12    pub(crate) placement: Option<Vec<u64>>,
13    /// Initial replica state for newly created shards. If empty - use Active state.
14    ///
15    /// # Warning
16    ///
17    /// Use with caution! Setting arbirray replica states here may break your Qdrant cluster.
18    pub(crate) initial_state: Option<Option<i32>>,
19}
20
21impl CreateShardKeyBuilder {
22    /// User-defined shard key
23    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    /// Number of shards to create per shard key
29    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    /// Number of replicas of each shard to create
35    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    /// List of peer ids, allowed to create shards. If empty - all peers are allowed
41    pub fn placement(self, value: Vec<u64>) -> Self {
42        let mut new = self;
43        new.placement = Option::Some(value);
44        new
45    }
46    /// Initial replica state for newly created shards.
47    ///
48    /// Uses Active state by default.
49    ///
50    /// # Warning
51    ///
52    /// Use with caution! Setting arbirray replica states here may break your Qdrant cluster.
53    #[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    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
70    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    /// Builds the desired type. Can often be omitted.
94    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}