confluent_kafka/admin/describe_features_result.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//! The result of `Admin::describe_features`.
16
17use super::FeatureMetadata;
18use crate::common::KafkaFuture;
19
20/// The result of the [`describe_features_with_options`](crate::admin::Admin::describe_features_with_options)
21/// call.
22#[derive(Clone, Debug)]
23#[doc(alias = "org.apache.kafka.clients.admin.DescribeFeaturesResult")]
24pub struct DescribeFeaturesResult {
25 future: KafkaFuture<FeatureMetadata>,
26}
27
28impl DescribeFeaturesResult {
29 /// Creates a result wrapping the given future.
30 ///
31 /// This constructor is `protected` in Java only to allow internal
32 /// subclasses (e.g. `InternalDescribeFeaturesResult`) to reuse it. It is not
33 /// part of the public API contract, so it stays crate-private here.
34 #[doc(alias = "org.apache.kafka.clients.admin.DescribeFeaturesResult#DescribeFeaturesResult")]
35 pub(crate) fn new(future: KafkaFuture<FeatureMetadata>) -> Self {
36 Self { future }
37 }
38
39 /// Returns the future which completes with the cluster's feature metadata.
40 #[doc(alias = "org.apache.kafka.clients.admin.DescribeFeaturesResult#featureMetadata")]
41 pub fn feature_metadata(&self) -> KafkaFuture<FeatureMetadata> {
42 self.future.clone()
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49 use crate::common::internals::KafkaFutureImpl;
50 use std::collections::HashMap;
51
52 #[tokio::test]
53 async fn feature_metadata_resolves() {
54 let handle: KafkaFutureImpl<FeatureMetadata> = KafkaFutureImpl::new();
55 let result = DescribeFeaturesResult::new(handle.future());
56 let metadata = FeatureMetadata::new(HashMap::new(), Some(1), HashMap::new());
57 handle.complete(metadata.clone());
58 assert_eq!(result.feature_metadata().get().await.unwrap(), metadata);
59 }
60}