Skip to main content

confluent_kafka/admin/
admin_client.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 entry point that creates an [`Admin`] client.
16
17use crate::admin::{Admin, AdminClientConfig, KafkaAdminClient};
18use crate::common::Error;
19
20/// The base class for in-built admin clients.
21///
22/// Client code should use the newer `Admin` interface in preference to this
23/// class.
24///
25/// # Translation notes
26///
27/// An uninhabited type: a namespace for [`AdminClient::create`], never a
28/// value.
29#[derive(Debug)]
30#[non_exhaustive]
31#[doc(alias = "org.apache.kafka.clients.admin.AdminClient")]
32pub enum AdminClient {}
33
34impl AdminClient {
35    /// Create a new Admin with the given configuration.
36    ///
37    /// # Arguments
38    ///
39    /// - `config` - The configuration.
40    ///
41    /// # Returns
42    ///
43    /// The new KafkaAdminClient.
44    ///
45    /// # Errors
46    ///
47    /// - `Error::is_kafka_error` (`Failed to create new KafkaAdminClient`, the
48    ///   cause as its source) if neither or both of `bootstrap.servers` and
49    ///   `bootstrap.controllers` are set, the bootstrap addresses cannot be
50    ///   resolved, the channel builder cannot be created, or
51    ///   `default.api.timeout.ms` is set explicitly below `request.timeout.ms`.
52    ///   For the first and the last the source answers `Error::is_config_error`,
53    ///   as Java's `KafkaAdminClient.determineBootstrapType` and
54    ///   `KafkaAdminClient.configureDefaultApiTimeoutMs` throw.
55    ///
56    /// # Panics
57    ///
58    /// If called outside a Tokio runtime, which runs the client's background
59    /// task.
60    ///
61    /// # Translation notes
62    ///
63    /// Takes the parsed `AdminClientConfig`, not Java's map.
64    #[doc(alias = "org.apache.kafka.clients.admin.AdminClient#create")]
65    pub fn create(config: AdminClientConfig) -> Result<Box<dyn Admin>, Error> {
66        Ok(Box::new(KafkaAdminClient::new(config)?))
67    }
68}