Skip to main content

kafka_client_engine/admin/describe_topic_partitions/
model.rs

1//! Engine-owned inert intent for one explicit topic-partition page.
2
3use kafka_client_core::{
4    DescribeTopicPartitionsCursor, DescribeTopicPartitionsPlan, DescribeTopicPartitionsPlanError,
5};
6
7/// Stable explicit cursor for a first or separately requested next page.
8#[derive(Clone, Debug, Eq, PartialEq)]
9pub struct AdminDescribeTopicPartitionsCursor {
10    topic_name: String,
11    partition_index: i32,
12}
13
14impl AdminDescribeTopicPartitionsCursor {
15    /// Creates inert cursor intent validated at the public operation boundary.
16    pub const fn new(topic_name: String, partition_index: i32) -> Self {
17        Self {
18            topic_name,
19            partition_index,
20        }
21    }
22
23    /// Returns the exact topic name.
24    pub fn topic_name(&self) -> &str {
25        &self.topic_name
26    }
27
28    /// Returns the requested first partition index.
29    pub const fn partition_index(&self) -> i32 {
30        self.partition_index
31    }
32
33    /// Consumes this cursor into stable scalar parts.
34    pub fn into_parts(self) -> (String, i32) {
35        (self.topic_name, self.partition_index)
36    }
37
38    pub(crate) fn canonicalize(mut self) -> Self {
39        self.topic_name = self.topic_name.into_boxed_str().into_string();
40        self
41    }
42
43    pub(crate) fn into_core(
44        self,
45    ) -> Result<DescribeTopicPartitionsCursor, DescribeTopicPartitionsPlanError> {
46        DescribeTopicPartitionsCursor::new(self.topic_name, self.partition_index)
47    }
48}
49
50/// Caller-ordered selection and explicit controls for exactly one page.
51#[derive(Clone, Debug, Eq, PartialEq)]
52pub struct AdminDescribeTopicPartitionsRequest {
53    topics: Vec<String>,
54    response_partition_limit: u32,
55    cursor: Option<AdminDescribeTopicPartitionsCursor>,
56}
57
58impl AdminDescribeTopicPartitionsRequest {
59    /// Creates inert page intent validated only after deadline capture.
60    pub const fn new(
61        topics: Vec<String>,
62        response_partition_limit: u32,
63        cursor: Option<AdminDescribeTopicPartitionsCursor>,
64    ) -> Self {
65        Self {
66            topics,
67            response_partition_limit,
68            cursor,
69        }
70    }
71
72    /// Consumes this inert request into stable owned parts.
73    pub fn into_parts(self) -> (Vec<String>, u32, Option<AdminDescribeTopicPartitionsCursor>) {
74        (self.topics, self.response_partition_limit, self.cursor)
75    }
76
77    pub(crate) fn canonicalize(mut self) -> Self {
78        self.topics = self
79            .topics
80            .into_iter()
81            .map(|topic| topic.into_boxed_str().into_string())
82            .collect();
83        self.topics.shrink_to_fit();
84        self.cursor = self
85            .cursor
86            .map(AdminDescribeTopicPartitionsCursor::canonicalize);
87        self
88    }
89
90    pub(crate) fn into_plan(
91        self,
92    ) -> Result<DescribeTopicPartitionsPlan, DescribeTopicPartitionsPlanError> {
93        let cursor = self
94            .cursor
95            .map(AdminDescribeTopicPartitionsCursor::into_core)
96            .transpose()?;
97        DescribeTopicPartitionsPlan::new(self.topics, self.response_partition_limit, cursor)
98    }
99}