crabka_connect/ids.rs
1//! Newtypes over the connector-offset maps.
2//!
3//! A [`SourceOffset`](crate::SourceOffset) is a pair of [`OffsetMap`]s: one
4//! naming *which* stream a position belongs to, one naming *where* in that
5//! stream. Both are the same `BTreeMap<String, OffsetValue>`, so a raw-map
6//! signature lets the two be transposed at a call site and still compile — a
7//! silent corruption of every persisted checkpoint. [`PartitionMap`] and
8//! [`PositionMap`] give the two halves distinct types so the compiler rejects
9//! the swap.
10
11use derive_more::{Deref, From, Into};
12use serde::{Deserialize, Serialize};
13
14use crate::record::OffsetMap;
15
16/// The stream-identifying half of a [`SourceOffset`](crate::SourceOffset) —
17/// Kafka Connect's `sourcePartition`. Names *which* stream a position belongs
18/// to (a database table, a file path, a log shard).
19///
20/// `#[serde(transparent)]` keeps the serialised checkpoint byte-identical to
21/// the bare map, so persisted offsets round-trip unchanged. [`Deref`] exposes
22/// the underlying map's read API (`get`, `contains_key`, …) at the call site.
23#[derive(Debug, Clone, PartialEq, Default, Deref, From, Into, Serialize, Deserialize)]
24#[serde(transparent)]
25pub struct PartitionMap(pub OffsetMap);
26
27/// The position-within-a-stream half of a [`SourceOffset`](crate::SourceOffset)
28/// — Kafka Connect's `sourceOffset`. Names *where* in the stream reading has
29/// reached (a log sequence number, a byte offset, a row id).
30///
31/// `#[serde(transparent)]` keeps the serialised checkpoint byte-identical to
32/// the bare map, so persisted offsets round-trip unchanged. [`Deref`] exposes
33/// the underlying map's read API (`get`, `contains_key`, …) at the call site.
34#[derive(Debug, Clone, PartialEq, Default, Deref, From, Into, Serialize, Deserialize)]
35#[serde(transparent)]
36pub struct PositionMap(pub OffsetMap);