confluent_kafka/admin/options/describe_cluster_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 `Admin::describe_cluster`.
16
17/// Options for `Admin::describe_cluster`.
18#[derive(Clone, Debug, Default)]
19#[doc(alias = "org.apache.kafka.clients.admin.DescribeClusterOptions")]
20pub struct DescribeClusterOptions {
21 timeout_ms: Option<i32>,
22 include_authorized_operations: bool,
23 include_fenced_brokers: bool,
24}
25
26impl DescribeClusterOptions {
27 /// Creates default options.
28 #[doc(alias = "org.apache.kafka.clients.admin.DescribeClusterOptions#DescribeClusterOptions")]
29 pub fn new() -> Self {
30 Self::default()
31 }
32
33 /// Set the timeout in milliseconds for this operation, or `None` if the default
34 /// API timeout for the `AdminClient` should be used.
35 ///
36 /// # Arguments
37 ///
38 /// - `timeout_ms` - the timeout in milliseconds, or `None` for the default API timeout.
39 ///
40 /// # Returns
41 ///
42 /// This `DescribeClusterOptions` instance.
43 #[must_use]
44 #[doc(alias = "org.apache.kafka.clients.admin.DescribeClusterOptions#timeoutMs")]
45 pub fn set_timeout_ms(mut self, timeout_ms: Option<i32>) -> Self {
46 self.timeout_ms = timeout_ms;
47 self
48 }
49
50 /// Returns the timeout in milliseconds for this operation, or `None` if the
51 /// default API timeout for the `AdminClient` should be used.
52 #[doc(alias = "org.apache.kafka.clients.admin.DescribeClusterOptions#timeoutMs")]
53 pub fn timeout_ms(&self) -> Option<i32> {
54 self.timeout_ms
55 }
56
57 /// Sets whether to include cluster authorized operations.
58 ///
59 /// # Arguments
60 ///
61 /// - `include_authorized_operations` - `true` to request the authorized operations.
62 ///
63 /// # Returns
64 ///
65 /// This `DescribeClusterOptions` instance.
66 #[must_use]
67 #[doc(alias = "org.apache.kafka.clients.admin.DescribeClusterOptions#includeAuthorizedOperations")]
68 pub fn set_include_authorized_operations(mut self, include_authorized_operations: bool) -> Self {
69 self.include_authorized_operations = include_authorized_operations;
70 self
71 }
72
73 /// Specify if authorized operations should be included in the response. Note that some
74 /// older brokers cannot supply this information even if it is requested.
75 ///
76 /// # Returns
77 ///
78 /// `true` if authorized operations are requested.
79 #[doc(alias = "org.apache.kafka.clients.admin.DescribeClusterOptions#includeAuthorizedOperations")]
80 pub fn include_authorized_operations(&self) -> bool {
81 self.include_authorized_operations
82 }
83
84 /// Sets whether to include fenced brokers in the response.
85 ///
86 /// # Arguments
87 ///
88 /// - `include_fenced_brokers` - `true` to request the fenced brokers.
89 ///
90 /// # Returns
91 ///
92 /// This `DescribeClusterOptions` instance.
93 #[must_use]
94 #[doc(alias = "org.apache.kafka.clients.admin.DescribeClusterOptions#includeFencedBrokers")]
95 pub fn set_include_fenced_brokers(mut self, include_fenced_brokers: bool) -> Self {
96 self.include_fenced_brokers = include_fenced_brokers;
97 self
98 }
99
100 /// Specify if fenced brokers should be included in the response. Note that some
101 /// older brokers cannot supply this information even if it is requested.
102 ///
103 /// # Returns
104 ///
105 /// `true` if fenced brokers are requested.
106 #[doc(alias = "org.apache.kafka.clients.admin.DescribeClusterOptions#includeFencedBrokers")]
107 pub fn include_fenced_brokers(&self) -> bool {
108 self.include_fenced_brokers
109 }
110}
111
112#[cfg(test)]
113mod tests {
114 use super::*;
115
116 #[test]
117 fn defaults_match_java() {
118 let options = DescribeClusterOptions::new();
119 assert_eq!(options.timeout_ms(), None);
120 assert!(!options.include_authorized_operations());
121 assert!(!options.include_fenced_brokers());
122 }
123
124 #[test]
125 fn fluent_setters() {
126 let options = DescribeClusterOptions::new()
127 .set_include_authorized_operations(true)
128 .set_include_fenced_brokers(true)
129 .set_timeout_ms(Some(1000));
130 assert!(options.include_authorized_operations());
131 assert!(options.include_fenced_brokers());
132 assert_eq!(options.timeout_ms(), Some(1000));
133 }
134}