Skip to main content

confluent_kafka/admin/
describe_consumer_groups_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_consumer_groups`.
16
17use std::collections::HashMap;
18
19use crate::admin::ConsumerGroupDescription;
20use crate::common::KafkaFuture;
21
22/// The result of `Admin::describe_consumer_groups`.
23#[derive(Clone, Debug)]
24#[doc(alias = "org.apache.kafka.clients.admin.DescribeConsumerGroupsResult")]
25pub struct DescribeConsumerGroupsResult {
26    futures: HashMap<String, KafkaFuture<ConsumerGroupDescription>>,
27}
28
29impl DescribeConsumerGroupsResult {
30    /// Creates a result from the per-group-id futures.
31    ///
32    /// # Arguments
33    ///
34    /// - `futures` - the future of each group id.
35    #[doc(alias = "org.apache.kafka.clients.admin.DescribeConsumerGroupsResult#DescribeConsumerGroupsResult")]
36    pub fn new(futures: HashMap<String, KafkaFuture<ConsumerGroupDescription>>) -> Self {
37        Self { futures }
38    }
39
40    /// Returns a map from group id to futures yielding group descriptions.
41    #[doc(alias = "org.apache.kafka.clients.admin.DescribeConsumerGroupsResult#describedGroups")]
42    pub fn described_groups(&self) -> HashMap<String, KafkaFuture<ConsumerGroupDescription>> {
43        self.futures.clone()
44    }
45
46    /// Returns a future yielding all descriptions if all describes succeed.
47    #[doc(alias = "org.apache.kafka.clients.admin.DescribeConsumerGroupsResult#all")]
48    pub fn all(&self) -> KafkaFuture<HashMap<String, ConsumerGroupDescription>> {
49        KafkaFuture::join_map(self.futures.iter().map(|(k, v)| (k.clone(), v.clone())).collect())
50    }
51}