use kafka_client_core::{
AlterReplicaLogDirAssignment as CoreAssignment, AlterReplicaLogDirsPlan,
AlterReplicaLogDirsPlanError,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AlterReplicaLogDirAssignment {
topic: String,
partition: i32,
broker_id: i32,
target_path: String,
}
impl AlterReplicaLogDirAssignment {
pub const fn new(topic: String, partition: i32, broker_id: i32, target_path: String) -> Self {
Self {
topic,
partition,
broker_id,
target_path,
}
}
pub fn into_parts(self) -> (String, i32, i32, String) {
(self.topic, self.partition, self.broker_id, self.target_path)
}
fn canonicalize(mut self) -> Self {
self.topic = self.topic.into_boxed_str().into_string();
self.target_path = self.target_path.into_boxed_str().into_string();
self
}
fn into_core(self) -> CoreAssignment {
CoreAssignment::new(self.broker_id, self.topic, self.partition, self.target_path)
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AlterReplicaLogDirsRequest {
assignments: Vec<AlterReplicaLogDirAssignment>,
}
impl AlterReplicaLogDirsRequest {
pub const fn new(assignments: Vec<AlterReplicaLogDirAssignment>) -> Self {
Self { assignments }
}
pub(crate) fn canonicalize(mut self) -> Self {
self.assignments = self
.assignments
.into_iter()
.map(AlterReplicaLogDirAssignment::canonicalize)
.collect();
self.assignments.shrink_to_fit();
self
}
pub(crate) fn into_plan(self) -> Result<AlterReplicaLogDirsPlan, AlterReplicaLogDirsPlanError> {
AlterReplicaLogDirsPlan::new(
self.assignments
.into_iter()
.map(AlterReplicaLogDirAssignment::into_core)
.collect(),
)
}
}