confluent_kafka/admin/options/elect_leaders_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::elect_leaders`.
16
17/// Options for `Admin::elect_leaders`.
18#[derive(Clone, Debug, Default)]
19#[doc(alias = "org.apache.kafka.clients.admin.ElectLeadersOptions")]
20pub struct ElectLeadersOptions {
21 timeout_ms: Option<i32>,
22}
23
24impl ElectLeadersOptions {
25 /// Creates default options (default API timeout).
26 #[doc(alias = "org.apache.kafka.clients.admin.ElectLeadersOptions#ElectLeadersOptions")]
27 pub fn new() -> Self {
28 Self::default()
29 }
30
31 /// Set the timeout in milliseconds for this operation, or `None` if the default
32 /// API timeout for the `AdminClient` should be used.
33 ///
34 /// # Arguments
35 ///
36 /// - `timeout_ms` - the timeout in milliseconds, or `None` for the default API timeout.
37 ///
38 /// # Returns
39 ///
40 /// This `ElectLeadersOptions` instance.
41 #[must_use]
42 #[doc(alias = "org.apache.kafka.clients.admin.AbstractOptions#timeoutMs")]
43 pub fn set_timeout_ms(mut self, timeout_ms: Option<i32>) -> Self {
44 self.timeout_ms = timeout_ms;
45 self
46 }
47
48 /// Returns the timeout in milliseconds for this operation, or `None` if the
49 /// default API timeout for the `AdminClient` should be used.
50 #[doc(alias = "org.apache.kafka.clients.admin.AbstractOptions#timeoutMs")]
51 pub fn timeout_ms(&self) -> Option<i32> {
52 self.timeout_ms
53 }
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn defaults_match_java() {
62 assert_eq!(ElectLeadersOptions::new().timeout_ms(), None);
63 }
64
65 #[test]
66 fn fluent_timeout() {
67 assert_eq!(ElectLeadersOptions::new().set_timeout_ms(Some(100)).timeout_ms(), Some(100));
68 }
69}