Skip to main content

confluent_kafka/admin/options/
describe_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 `Admin::describe_topics_with_topics`.
16
17/// Default maximum number of partitions to be returned in a single response.
18const DEFAULT_PARTITION_SIZE_LIMIT_PER_RESPONSE: i32 = 2000;
19
20/// Options for `Admin::describe_topics_with_topics`.
21#[derive(Clone, Debug)]
22#[doc(alias = "org.apache.kafka.clients.admin.DescribeTopicsOptions")]
23pub struct DescribeTopicsOptions {
24    timeout_ms: Option<i32>,
25    include_authorized_operations: bool,
26    partition_size_limit_per_response: i32,
27}
28
29impl Default for DescribeTopicsOptions {
30    fn default() -> Self {
31        Self {
32            timeout_ms: None,
33            include_authorized_operations: false,
34            partition_size_limit_per_response: DEFAULT_PARTITION_SIZE_LIMIT_PER_RESPONSE,
35        }
36    }
37}
38
39impl DescribeTopicsOptions {
40    /// Creates default options.
41    #[doc(alias = "org.apache.kafka.clients.admin.DescribeTopicsOptions#DescribeTopicsOptions")]
42    pub fn new() -> Self {
43        Self::default()
44    }
45
46    /// Set the timeout in milliseconds for this operation, or `None` if the default
47    /// API timeout for the `AdminClient` should be used.
48    ///
49    /// # Arguments
50    ///
51    /// - `timeout_ms` - the timeout in milliseconds, or `None` for the default API timeout.
52    ///
53    /// # Returns
54    ///
55    /// This `DescribeTopicsOptions` instance.
56    #[must_use]
57    #[doc(alias = "org.apache.kafka.clients.admin.DescribeTopicsOptions#timeoutMs")]
58    pub fn set_timeout_ms(mut self, timeout_ms: Option<i32>) -> Self {
59        self.timeout_ms = timeout_ms;
60        self
61    }
62
63    /// Returns the timeout in milliseconds for this operation, or `None` if the
64    /// default API timeout for the `AdminClient` should be used.
65    #[doc(alias = "org.apache.kafka.clients.admin.DescribeTopicsOptions#timeoutMs")]
66    pub fn timeout_ms(&self) -> Option<i32> {
67        self.timeout_ms
68    }
69
70    /// Sets whether to include authorized operations for the described topics.
71    ///
72    /// # Arguments
73    ///
74    /// - `include_authorized_operations` - `true` to request the authorized operations.
75    ///
76    /// # Returns
77    ///
78    /// This `DescribeTopicsOptions` instance.
79    #[must_use]
80    #[doc(alias = "org.apache.kafka.clients.admin.DescribeTopicsOptions#includeAuthorizedOperations")]
81    pub fn set_include_authorized_operations(mut self, include_authorized_operations: bool) -> Self {
82        self.include_authorized_operations = include_authorized_operations;
83        self
84    }
85
86    /// Returns whether authorized operations are requested for the described topics.
87    #[doc(alias = "org.apache.kafka.clients.admin.DescribeTopicsOptions#includeAuthorizedOperations")]
88    pub fn include_authorized_operations(&self) -> bool {
89        self.include_authorized_operations
90    }
91
92    /// Sets the maximum number of partitions to be returned in a single response.
93    ///
94    /// **This option:**
95    /// - Is only effective when using topic names (not topic IDs).
96    /// - Will not be effective if it is larger than the server-side configuration
97    ///   `max.request.partition.size.limit`.
98    ///
99    /// # Arguments
100    ///
101    /// - `partition_size_limit_per_response` - the maximum number of partitions per response
102    ///
103    /// # Returns
104    ///
105    /// This `DescribeTopicsOptions` instance.
106    #[must_use]
107    #[doc(alias = "org.apache.kafka.clients.admin.DescribeTopicsOptions#partitionSizeLimitPerResponse")]
108    pub fn set_partition_size_limit_per_response(mut self, partition_size_limit_per_response: i32) -> Self {
109        self.partition_size_limit_per_response = partition_size_limit_per_response;
110        self
111    }
112
113    /// Returns the maximum number of partitions to be returned in a single response.
114    #[doc(alias = "org.apache.kafka.clients.admin.DescribeTopicsOptions#partitionSizeLimitPerResponse")]
115    pub fn partition_size_limit_per_response(&self) -> i32 {
116        self.partition_size_limit_per_response
117    }
118}
119
120#[cfg(test)]
121mod tests {
122    use super::*;
123
124    #[test]
125    fn defaults_match_java() {
126        let options = DescribeTopicsOptions::new();
127        assert_eq!(options.timeout_ms(), None);
128        assert!(!options.include_authorized_operations());
129        assert_eq!(options.partition_size_limit_per_response(), 2000);
130    }
131
132    #[test]
133    fn fluent_setters() {
134        let options = DescribeTopicsOptions::new()
135            .set_include_authorized_operations(true)
136            .set_partition_size_limit_per_response(50);
137        assert!(options.include_authorized_operations());
138        assert_eq!(options.partition_size_limit_per_response(), 50);
139    }
140}