atomr_persistence_aws/
keys.rs1pub const EVENT_PREFIX: &str = "E#";
4pub const SNAPSHOT_PREFIX: &str = "S#";
5
6const SK_WIDTH: usize = 20;
7
8pub fn event_sk(sequence_nr: u64) -> String {
9 format!("{EVENT_PREFIX}{seq:0width$}", seq = sequence_nr, width = SK_WIDTH)
10}
11
12pub fn snapshot_sk(sequence_nr: u64) -> String {
13 format!("{SNAPSHOT_PREFIX}{seq:0width$}", seq = sequence_nr, width = SK_WIDTH)
14}
15
16pub fn parse_sequence(sk: &str) -> Option<u64> {
17 let stripped = sk.strip_prefix(EVENT_PREFIX).or_else(|| sk.strip_prefix(SNAPSHOT_PREFIX))?;
18 stripped.parse().ok()
19}
20
21#[cfg(test)]
22mod tests {
23 use super::*;
24
25 #[test]
26 fn lex_order_matches_numeric() {
27 let low = event_sk(1);
28 let high = event_sk(1_000_000);
29 assert!(low < high, "{low} vs {high}");
30 }
31
32 #[test]
33 fn parse_round_trip() {
34 assert_eq!(parse_sequence(&event_sk(42)), Some(42));
35 assert_eq!(parse_sequence(&snapshot_sk(7)), Some(7));
36 assert_eq!(parse_sequence("bogus"), None);
37 }
38}