Skip to main content

confluent_kafka/admin/
unregister_controller_result.rs

1// Copyright 2026 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//! The result of `Admin::unregister_controller`.
16//!
17//! Added in Kafka 4.4 (KAFKA-20395).
18
19use crate::common::KafkaFuture;
20
21/// The result of the [`unregister_controller_with_options`](crate::admin::Admin::unregister_controller_with_options)
22/// call.
23///
24/// The API of this class is evolving, see [`Admin`](crate::admin::Admin) for details.
25#[derive(Clone, Debug)]
26#[doc(alias = "org.apache.kafka.clients.admin.UnregisterControllerResult")]
27pub struct UnregisterControllerResult {
28    future: KafkaFuture<()>,
29}
30
31impl UnregisterControllerResult {
32    /// Creates a result wrapping the given future. Package-private in Java.
33    #[doc(alias = "org.apache.kafka.clients.admin.UnregisterControllerResult#UnregisterControllerResult")]
34    pub(crate) fn new(future: KafkaFuture<()>) -> Self {
35        Self { future }
36    }
37
38    /// Returns a future which succeeds if the operation is successful.
39    #[doc(alias = "org.apache.kafka.clients.admin.UnregisterControllerResult#all")]
40    pub fn all(&self) -> KafkaFuture<()> {
41        self.future.clone()
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48    use crate::common::Error;
49    use crate::common::internals::KafkaFutureImpl;
50
51    #[tokio::test]
52    async fn all_resolves_with_the_wrapped_future() {
53        let handle: KafkaFutureImpl<()> = KafkaFutureImpl::new();
54        let result = UnregisterControllerResult::new(handle.future());
55        assert!(!result.all().is_done());
56        handle.complete(());
57        result.all().get().await.unwrap();
58    }
59
60    #[tokio::test]
61    async fn all_fails_with_the_wrapped_error() {
62        let handle: KafkaFutureImpl<()> = KafkaFutureImpl::new();
63        let result = UnregisterControllerResult::new(handle.future());
64        handle.complete_with_error(Error::local_illegal_state("boom"));
65        assert_eq!(result.all().get().await.unwrap_err().message(), "boom");
66    }
67}