Expand description
Idempotency key validation.
The Snippe API enforces a 30-byte maximum on the Idempotency-Key
header. Keys longer than 30 bytes don’t return a clear validation error —
they trigger the cryptic PAY_001 (“failed to initiate payment”) error,
which is hard to debug if you don’t know to look at the key length first.
This module exposes a newtype that enforces the constraint at construction time, so over-long keys can never reach the wire.
§Examples
use snippe::IdempotencyKey;
let key = IdempotencyKey::new("ord-12345-att-1")?;
assert_eq!(key.as_str(), "ord-12345-att-1");
// Length is enforced — this fails before any network call:
assert!(IdempotencyKey::new("a".repeat(31)).is_err());§Picking a key
- Per request, not per resource. The retry-safe semantics work because
the same key always returns the same cached response; if you reuse a key
across logically distinct calls you’ll get a
422idempotency conflict. - Short. 30 bytes leaves room for ~15-character prefixes plus a short
ID. Avoid
${userId}-${orderId}-${Date.now()}patterns — they easily overshoot. - Stable across retries of the same logical operation. Generate the key once when you first attempt the request, and reuse it on every retry.
Structs§
- Idempotency
Key - A validated idempotency key — non-empty and ≤ 30 bytes.
Enums§
- Idempotency
KeyError - Reasons construction of an
IdempotencyKeycan fail.
Constants§
- MAX_
LENGTH - Maximum byte length the Snippe API accepts on the
Idempotency-Keyheader.