Skip to main content

couchbase/options/
bucket_mgmt_options.rs

1/*
2 *
3 *  * Copyright (c) 2025 Couchbase, Inc.
4 *  *
5 *  * Licensed under the Apache License, Version 2.0 (the "License");
6 *  * you may not use this file except in compliance with the License.
7 *  * You may obtain a copy of the License at
8 *  *
9 *  *    http://www.apache.org/licenses/LICENSE-2.0
10 *  *
11 *  * Unless required by applicable law or agreed to in writing, software
12 *  * distributed under the License is distributed on an "AS IS" BASIS,
13 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  * See the License for the specific language governing permissions and
15 *  * limitations under the License.
16 *
17 */
18
19//! Options for bucket management operations.
20//!
21//! This module provides structures and implementations for options used in
22//! various bucket management operations, such as creating, updating, and
23//! deleting buckets. Each operation has an associated options struct that
24//! can be used to customize the behavior of the operation, including
25//! specifying a retry strategy in case of transient failures.
26use crate::retry::RetryStrategy;
27use std::sync::Arc;
28
29/// Options for [`BucketManager::get_all_buckets`](crate::management::buckets::bucket_manager::BucketManager::get_all_buckets).
30#[derive(Default, Debug, Clone)]
31#[non_exhaustive]
32pub struct GetAllBucketsOptions {
33    /// The retry strategy to use in case of transient failures.
34    pub retry_strategy: Option<Arc<dyn RetryStrategy>>,
35}
36
37impl GetAllBucketsOptions {
38    /// Creates a new instance of [`GetAllBucketsOptions`].
39    pub fn new() -> Self {
40        Default::default()
41    }
42
43    /// Sets the retry strategy.
44    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
45        self.retry_strategy = Some(retry_strategy);
46        self
47    }
48}
49
50/// Options for [`BucketManager::get_bucket`](crate::management::buckets::bucket_manager::BucketManager::get_bucket).
51#[derive(Default, Debug, Clone)]
52#[non_exhaustive]
53pub struct GetBucketOptions {
54    /// The retry strategy to use in case of transient failures.
55    pub retry_strategy: Option<Arc<dyn RetryStrategy>>,
56}
57
58impl GetBucketOptions {
59    /// Creates a new instance of [`GetBucketOptions`].
60    pub fn new() -> Self {
61        Default::default()
62    }
63
64    /// Sets the retry strategy.
65    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
66        self.retry_strategy = Some(retry_strategy);
67        self
68    }
69}
70
71/// Options for [`BucketManager::create_bucket`](crate::management::buckets::bucket_manager::BucketManager::create_bucket).
72#[derive(Default, Debug, Clone)]
73#[non_exhaustive]
74pub struct CreateBucketOptions {
75    /// The retry strategy to use in case of transient failures.
76    pub retry_strategy: Option<Arc<dyn RetryStrategy>>,
77}
78
79impl CreateBucketOptions {
80    /// Creates a new instance of [`CreateBucketOptions`].
81    pub fn new() -> Self {
82        Default::default()
83    }
84
85    /// Sets the retry strategy.
86    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
87        self.retry_strategy = Some(retry_strategy);
88        self
89    }
90}
91
92/// Options for [`BucketManager::update_bucket`](crate::management::buckets::bucket_manager::BucketManager::update_bucket).
93#[derive(Default, Debug, Clone)]
94#[non_exhaustive]
95pub struct UpdateBucketOptions {
96    /// The retry strategy to use in case of transient failures.
97    pub retry_strategy: Option<Arc<dyn RetryStrategy>>,
98}
99
100impl UpdateBucketOptions {
101    /// Creates a new instance of [`UpdateBucketOptions`].
102    pub fn new() -> Self {
103        Default::default()
104    }
105
106    /// Sets the retry strategy.
107    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
108        self.retry_strategy = Some(retry_strategy);
109        self
110    }
111}
112
113/// Options for [`BucketManager::drop_bucket`](crate::management::buckets::bucket_manager::BucketManager::drop_bucket).
114#[derive(Default, Debug, Clone)]
115#[non_exhaustive]
116pub struct DropBucketOptions {
117    /// The retry strategy to use in case of transient failures.
118    pub retry_strategy: Option<Arc<dyn RetryStrategy>>,
119}
120
121impl DropBucketOptions {
122    /// Creates a new instance of [`DropBucketOptions`].
123    pub fn new() -> Self {
124        Default::default()
125    }
126
127    /// Sets the retry strategy.
128    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
129        self.retry_strategy = Some(retry_strategy);
130        self
131    }
132}
133
134/// Options for [`BucketManager::flush_bucket`](crate::management::buckets::bucket_manager::BucketManager::flush_bucket).
135#[derive(Default, Debug, Clone)]
136#[non_exhaustive]
137pub struct FlushBucketOptions {
138    /// The retry strategy to use in case of transient failures.
139    pub retry_strategy: Option<Arc<dyn RetryStrategy>>,
140}
141
142impl FlushBucketOptions {
143    /// Creates a new instance of [`FlushBucketOptions`].
144    pub fn new() -> Self {
145        Default::default()
146    }
147
148    /// Sets the retry strategy.
149    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
150        self.retry_strategy = Some(retry_strategy);
151        self
152    }
153}