Skip to main content

qdrant_client/builders/
collection_params_diff_builder.rs

1use crate::qdrant::*;
2
3#[must_use]
4#[derive(Clone)]
5pub struct CollectionParamsDiffBuilder {
6    /// Number of replicas of each shard that network tries to maintain
7    pub(crate) replication_factor: Option<Option<u32>>,
8    /// How many replicas should apply the operation for us to consider it successful
9    pub(crate) write_consistency_factor: Option<Option<u32>>,
10    /// If true - point's payload will not be stored in memory
11    pub(crate) on_disk_payload: Option<Option<bool>>,
12    /// Fan-out every read request to these many additional remote nodes (and return first available response)
13    pub(crate) read_fan_out_factor: Option<Option<u32>>,
14    /// Fan-out delay in milliseconds. If set, the fan-out request will be delayed by this amount.
15    pub(crate) read_fan_out_delay_ms: Option<Option<u64>>,
16    /// Update params of the payload storage
17    pub(crate) payload: Option<Option<PayloadStorageParams>>,
18}
19#[allow(clippy::all)]
20#[allow(clippy::derive_partial_eq_without_eq)]
21impl CollectionParamsDiffBuilder {
22    /// Number of replicas of each shard that network tries to maintain
23    pub fn replication_factor(self, value: u32) -> Self {
24        let mut new = self;
25        new.replication_factor = Option::Some(Option::Some(value));
26        new
27    }
28    /// How many replicas should apply the operation for us to consider it successful
29    pub fn write_consistency_factor(self, value: u32) -> Self {
30        let mut new = self;
31        new.write_consistency_factor = Option::Some(Option::Some(value));
32        new
33    }
34    /// If true - point's payload will not be stored in memory
35    ///
36    /// Deprecated since 1.19.0, use [`payload`](Self::payload) instead.
37    pub fn on_disk_payload(self, value: bool) -> Self {
38        let mut new = self;
39        new.on_disk_payload = Option::Some(Option::Some(value));
40        new
41    }
42    /// Fan-out every read request to these many additional remote nodes (and return first available response)
43    pub fn read_fan_out_factor(self, value: u32) -> Self {
44        let mut new = self;
45        new.read_fan_out_factor = Option::Some(Option::Some(value));
46        new
47    }
48    /// Fan-out delay in milliseconds. If set, the fan-out request will be delayed by this amount.
49    pub fn read_fan_out_delay_ms(self, value: u64) -> Self {
50        let mut new = self;
51        new.read_fan_out_delay_ms = Option::Some(Option::Some(value));
52        new
53    }
54    /// Update params of the payload storage.
55    /// Overrides the deprecated `on_disk_payload` flag if both are set.
56    pub fn payload<VALUE: core::convert::Into<PayloadStorageParams>>(self, value: VALUE) -> Self {
57        let mut new = self;
58        new.payload = Option::Some(Option::Some(value.into()));
59        new
60    }
61
62    #[allow(deprecated)]
63    fn build_inner(self) -> Result<CollectionParamsDiff, std::convert::Infallible> {
64        Ok(CollectionParamsDiff {
65            replication_factor: match self.replication_factor {
66                Some(value) => value,
67                None => core::default::Default::default(),
68            },
69            write_consistency_factor: match self.write_consistency_factor {
70                Some(value) => value,
71                None => core::default::Default::default(),
72            },
73            on_disk_payload: match self.on_disk_payload {
74                Some(value) => value,
75                None => core::default::Default::default(),
76            },
77            read_fan_out_factor: match self.read_fan_out_factor {
78                Some(value) => value,
79                None => core::default::Default::default(),
80            },
81            read_fan_out_delay_ms: match self.read_fan_out_delay_ms {
82                Some(value) => value,
83                None => core::default::Default::default(),
84            },
85            payload: match self.payload {
86                Some(value) => value,
87                None => core::default::Default::default(),
88            },
89        })
90    }
91    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
92    fn create_empty() -> Self {
93        Self {
94            replication_factor: core::default::Default::default(),
95            write_consistency_factor: core::default::Default::default(),
96            on_disk_payload: core::default::Default::default(),
97            read_fan_out_factor: core::default::Default::default(),
98            read_fan_out_delay_ms: core::default::Default::default(),
99            payload: core::default::Default::default(),
100        }
101    }
102}
103
104impl From<CollectionParamsDiffBuilder> for CollectionParamsDiff {
105    fn from(value: CollectionParamsDiffBuilder) -> Self {
106        value.build_inner().unwrap_or_else(|_| {
107            panic!(
108                "Failed to convert {0} to {1}",
109                "CollectionParamsDiffBuilder", "CollectionParamsDiff"
110            )
111        })
112    }
113}
114
115impl CollectionParamsDiffBuilder {
116    /// Builds the desired type. Can often be omitted.
117    pub fn build(self) -> CollectionParamsDiff {
118        self.build_inner().unwrap_or_else(|_| {
119            panic!(
120                "Failed to build {0} into {1}",
121                "CollectionParamsDiffBuilder", "CollectionParamsDiff"
122            )
123        })
124    }
125}
126
127impl Default for CollectionParamsDiffBuilder {
128    fn default() -> Self {
129        Self::create_empty()
130    }
131}