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}
14
15impl CreateShardKeyBuilder {
16    /// User-defined shard key
17    #[allow(unused_mut)]
18    pub fn shard_key<VALUE: core::convert::Into<ShardKey>>(self, value: VALUE) -> Self {
19        let mut new = self;
20        new.shard_key = Option::Some(Option::Some(value.into()));
21        new
22    }
23    /// Number of shards to create per shard key
24    #[allow(unused_mut)]
25    pub fn shards_number(self, value: u32) -> Self {
26        let mut new = self;
27        new.shards_number = Option::Some(Option::Some(value));
28        new
29    }
30    /// Number of replicas of each shard to create
31    #[allow(unused_mut)]
32    pub fn replication_factor(self, value: u32) -> Self {
33        let mut new = self;
34        new.replication_factor = Option::Some(Option::Some(value));
35        new
36    }
37    /// List of peer ids, allowed to create shards. If empty - all peers are allowed
38    #[allow(unused_mut)]
39    pub fn placement(self, value: Vec<u64>) -> Self {
40        let mut new = self;
41        new.placement = Option::Some(value);
42        new
43    }
44    fn build_inner(self) -> Result<CreateShardKey, std::convert::Infallible> {
45        Ok(CreateShardKey {
46            shard_key: self.shard_key.unwrap_or_default(),
47            shards_number: self.shards_number.unwrap_or_default(),
48            replication_factor: self.replication_factor.unwrap_or_default(),
49            placement: self.placement.unwrap_or_default(),
50        })
51    }
52    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
53    fn create_empty() -> Self {
54        Self {
55            shard_key: core::default::Default::default(),
56            shards_number: core::default::Default::default(),
57            replication_factor: core::default::Default::default(),
58            placement: core::default::Default::default(),
59        }
60    }
61}
62
63impl From<CreateShardKeyBuilder> for CreateShardKey {
64    fn from(value: CreateShardKeyBuilder) -> Self {
65        value.build_inner().unwrap_or_else(|_| {
66            panic!(
67                "Failed to convert {0} to {1}",
68                "CreateShardKeyBuilder", "CreateShardKey"
69            )
70        })
71    }
72}
73
74impl CreateShardKeyBuilder {
75    /// Builds the desired type. Can often be omitted.
76    pub fn build(self) -> CreateShardKey {
77        self.build_inner().unwrap_or_else(|_| {
78            panic!(
79                "Failed to build {0} into {1}",
80                "CreateShardKeyBuilder", "CreateShardKey"
81            )
82        })
83    }
84}
85
86impl Default for CreateShardKeyBuilder {
87    fn default() -> Self {
88        Self::create_empty()
89    }
90}