Skip to main content

confluent_kafka/admin/options/
delete_topics_options.rs

1// Copyright 2025 Confluent Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Options for the `Admin::delete_topics_with_*` methods.
16
17/// Options for `Admin::delete_topics_with_topic_collection_options`.
18#[derive(Clone, Debug)]
19#[doc(alias = "org.apache.kafka.clients.admin.DeleteTopicsOptions")]
20pub struct DeleteTopicsOptions {
21    timeout_ms: Option<i32>,
22    retry_on_quota_violation: bool,
23}
24
25impl Default for DeleteTopicsOptions {
26    fn default() -> Self {
27        Self { timeout_ms: None, retry_on_quota_violation: true }
28    }
29}
30
31impl DeleteTopicsOptions {
32    /// Creates default options (`retry_on_quota_violation=true`, default API
33    /// timeout).
34    #[doc(alias = "org.apache.kafka.clients.admin.DeleteTopicsOptions#DeleteTopicsOptions")]
35    pub fn new() -> Self {
36        Self::default()
37    }
38
39    /// Set the timeout in milliseconds for this operation, or `None` if the default
40    /// API timeout for the `AdminClient` should be used.
41    ///
42    /// # Arguments
43    ///
44    /// - `timeout_ms` - the timeout in milliseconds, or `None` for the default API timeout.
45    ///
46    /// # Returns
47    ///
48    /// This `DeleteTopicsOptions` instance.
49    #[must_use]
50    #[doc(alias = "org.apache.kafka.clients.admin.DeleteTopicsOptions#timeoutMs")]
51    pub fn set_timeout_ms(mut self, timeout_ms: Option<i32>) -> Self {
52        self.timeout_ms = timeout_ms;
53        self
54    }
55
56    /// Returns the timeout in milliseconds for this operation, or `None` if the
57    /// default API timeout for the `AdminClient` should be used.
58    #[doc(alias = "org.apache.kafka.clients.admin.DeleteTopicsOptions#timeoutMs")]
59    pub fn timeout_ms(&self) -> Option<i32> {
60        self.timeout_ms
61    }
62
63    /// Set to true if quota violation should be automatically retried.
64    ///
65    /// # Arguments
66    ///
67    /// - `retry_on_quota_violation` - `true` to retry on quota violation.
68    ///
69    /// # Returns
70    ///
71    /// This `DeleteTopicsOptions` instance.
72    #[must_use]
73    #[doc(alias = "org.apache.kafka.clients.admin.DeleteTopicsOptions#retryOnQuotaViolation")]
74    pub fn set_retry_on_quota_violation(mut self, retry_on_quota_violation: bool) -> Self {
75        self.retry_on_quota_violation = retry_on_quota_violation;
76        self
77    }
78
79    /// Returns true if quota violation should be automatically retried.
80    #[doc(alias = "org.apache.kafka.clients.admin.DeleteTopicsOptions#shouldRetryOnQuotaViolation")]
81    pub fn should_retry_on_quota_violation(&self) -> bool {
82        self.retry_on_quota_violation
83    }
84}
85
86#[cfg(test)]
87mod tests {
88    use super::*;
89
90    #[test]
91    fn defaults_match_java() {
92        let options = DeleteTopicsOptions::new();
93        assert_eq!(options.timeout_ms(), None);
94        assert!(options.should_retry_on_quota_violation());
95    }
96
97    #[test]
98    fn fluent_setters() {
99        let options = DeleteTopicsOptions::new()
100            .set_timeout_ms(Some(1000))
101            .set_retry_on_quota_violation(false);
102        assert_eq!(options.timeout_ms(), Some(1000));
103        assert!(!options.should_retry_on_quota_violation());
104    }
105}