use super::{
ProducerTrySendAccepted, ProducerTrySendError, ProducerTrySendErrorKind, record::ProducerRecord,
};
#[must_use = "accepted batch work owns terminal observers"]
pub struct ProducerTrySendBatch {
accepted: Vec<ProducerTrySendAccepted>,
rejection: Option<ProducerTrySendBatchError>,
}
impl ProducerTrySendBatch {
pub(super) const fn new(
accepted: Vec<ProducerTrySendAccepted>,
rejection: Option<ProducerTrySendBatchError>,
) -> Self {
Self {
accepted,
rejection,
}
}
pub fn into_parts(
self,
) -> (
Vec<ProducerTrySendAccepted>,
Option<ProducerTrySendBatchError>,
) {
(self.accepted, self.rejection)
}
}
impl std::fmt::Debug for ProducerTrySendBatch {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("ProducerTrySendBatch")
.field("accepted", &self.accepted.len())
.field("rejection", &self.rejection)
.finish()
}
}
#[derive(Debug)]
pub struct ProducerTrySendBatchError {
kind: ProducerTrySendErrorKind,
records: Vec<ProducerRecord>,
detail: Option<String>,
}
impl ProducerTrySendBatchError {
pub const fn kind(&self) -> ProducerTrySendErrorKind {
self.kind
}
pub fn records(&self) -> &[ProducerRecord] {
&self.records
}
pub fn detail(&self) -> Option<&str> {
self.detail.as_deref()
}
pub fn into_records(self) -> Vec<ProducerRecord> {
self.records
}
pub fn into_parts(
self,
) -> (
ProducerTrySendErrorKind,
Vec<ProducerRecord>,
Option<String>,
) {
(self.kind, self.records, self.detail)
}
pub(super) fn from_single(
error: ProducerTrySendError,
mut remaining: Vec<ProducerRecord>,
) -> Self {
let (kind, first, detail) = error.into_parts();
remaining.insert(0, first);
Self {
kind,
records: remaining,
detail,
}
}
pub(super) const fn from_parts(
kind: ProducerTrySendErrorKind,
records: Vec<ProducerRecord>,
detail: Option<String>,
) -> Self {
Self {
kind,
records,
detail,
}
}
}