Skip to content

Commit e175be3

Browse files
refactor(har-abi): forbid(unsafe_code) + unify abi_tag → to_abi_tag (#113)
Two small polish items from reviewing the shared `har-abi` crate: - Add **`#![forbid(unsafe_code)]`** — every other HAR crate has it and har-abi has zero unsafe; this just makes it consistent and enforced. - Rename **`DeliveryGuarantee::abi_tag` → `to_abi_tag`** so all five tag enums expose the same method name (`to_abi_tag` / `from_abi_tag`). `DeliveryGuarantee` was the odd one out. All call sites are internal to har-abi, so this is non-breaking for external consumers (there are none yet). No behaviour change. `cargo test` / `clippy -D warnings` / `fmt --check` all green. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d873cc7 commit e175be3

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

crates/har-abi/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
//! - the wire codec ([`RoutedEnvelope`], [`RoutedReceipt`]);
2222
//! - the canonical queue-naming scheme ([`inbound_queue`], [`receipt_queue`]).
2323
24+
#![forbid(unsafe_code)]
25+
2426
use serde::{Deserialize, Serialize};
2527
use std::collections::BTreeMap;
2628

@@ -57,8 +59,9 @@ pub enum DeliveryGuarantee {
5759
}
5860

5961
impl DeliveryGuarantee {
60-
/// The C-ABI tag byte. MUST match the spec and proven-queueconn.
61-
pub fn abi_tag(self) -> u8 {
62+
/// The C-ABI tag byte. MUST match the spec and proven-queueconn. Named
63+
/// `to_abi_tag` to match the other tag enums' method for a uniform surface.
64+
pub fn to_abi_tag(self) -> u8 {
6265
match self {
6366
Self::AtMostOnce => 0,
6467
Self::AtLeastOnce => 1,
@@ -272,7 +275,7 @@ impl RoutedEnvelope {
272275
event_id: event_id.into(),
273276
category: category.into(),
274277
priority,
275-
guarantee: guarantee.abi_tag(),
278+
guarantee: guarantee.to_abi_tag(),
276279
content_type: content_type.into(),
277280
payload,
278281
headers: BTreeMap::new(),
@@ -395,9 +398,9 @@ mod conformance {
395398
fn tag_values_match_the_spec() {
396399
assert_eq!(ABI_VERSION, 1);
397400

398-
assert_eq!(DeliveryGuarantee::AtMostOnce.abi_tag(), 0);
399-
assert_eq!(DeliveryGuarantee::AtLeastOnce.abi_tag(), 1);
400-
assert_eq!(DeliveryGuarantee::ExactlyOnce.abi_tag(), 2);
401+
assert_eq!(DeliveryGuarantee::AtMostOnce.to_abi_tag(), 0);
402+
assert_eq!(DeliveryGuarantee::AtLeastOnce.to_abi_tag(), 1);
403+
assert_eq!(DeliveryGuarantee::ExactlyOnce.to_abi_tag(), 2);
401404

402405
assert_eq!(QueueOp::Publish.to_abi_tag(), 0);
403406
assert_eq!(QueueOp::Purge.to_abi_tag(), 5);
@@ -420,7 +423,7 @@ mod conformance {
420423
fn all_tags_round_trip_and_reject_out_of_range() {
421424
for tag in 0u8..3 {
422425
assert_eq!(
423-
DeliveryGuarantee::from_abi_tag(tag).map(|v| v.abi_tag()),
426+
DeliveryGuarantee::from_abi_tag(tag).map(|v| v.to_abi_tag()),
424427
Some(tag)
425428
);
426429
}

0 commit comments

Comments
 (0)