Skip to main content

kafka_client_engine/consumer/assigned_host/
assignment_capture.rs

1//! Linear deadline capture bound to one assigned-consumer handle and operation.
2
3use crate::clock::DeadlineCapture;
4
5use super::{
6    AssignedConsumerAssignment, AssignedConsumerHandle,
7    assignment_result::{
8        AssignedConsumerTryReplaceAssignmentAccepted, AssignedConsumerTryReplaceAssignmentError,
9    },
10};
11
12/// One absolute assignment deadline bound to one mutably borrowed handle.
13///
14/// Consuming this token is the only way to admit the corresponding assignment,
15/// so safe Rust prevents reuse or admission through another handle.
16#[must_use = "dropping abandons the captured deadline without admitting assignment work"]
17pub struct AssignedConsumerAssignmentCapture<'handle> {
18    handle: &'handle mut AssignedConsumerHandle,
19    deadline: DeadlineCapture,
20}
21
22impl<'handle> AssignedConsumerAssignmentCapture<'handle> {
23    pub(super) const fn bind_deadline_to_handle(
24        handle: &'handle mut AssignedConsumerHandle,
25        deadline: DeadlineCapture,
26    ) -> Self {
27        Self { handle, deadline }
28    }
29
30    /// Consumes this exact capture while attempting all-or-nothing admission.
31    pub fn try_replace_assignment(
32        self,
33        entries: Vec<AssignedConsumerAssignment>,
34    ) -> Result<
35        AssignedConsumerTryReplaceAssignmentAccepted,
36        AssignedConsumerTryReplaceAssignmentError,
37    > {
38        self.handle
39            .try_replace_assignment_captured(entries, self.deadline)
40    }
41}
42
43impl std::fmt::Debug for AssignedConsumerAssignmentCapture<'_> {
44    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45        formatter
46            .debug_struct("AssignedConsumerAssignmentCapture")
47            .finish_non_exhaustive()
48    }
49}