SOL-XPILE-003 // xpile
Python Token-Bucket Rate Limiter to Rust
Lift a typed Python token-bucket middleware into a deterministic Rust rate limiter via xpile's Python frontend.
Measured delta: Zero negative token underflows; 2,000/2,000 burst parity checks
Before (Failing Anti-Pattern)
def allow_untyped(tokens, cost):
return tokens - cost # allows negative token underflow!
After (Verified Code)
def allow_request(tokens: int, cost: int) -> int:
if tokens >= cost:
return tokens - cost
return tokens
Verification Contract
schema: xpile.contract.v1 source_lang: python target_lang: rust invariants: - tokens_non_negative: true - deterministic_clock: true
Verified CLI Command & Output
$ xpile transpile limiter.py --target rust // xpile-generated from Python module limiter