reliakit-bulkhead 0.1.0

Clock-agnostic concurrency limiter (counting-semaphore bulkhead) that caps in-flight operations. no_std and zero-dependency.
Documentation
  • Coverage
  • 100%
    14 out of 14 items documented1 out of 13 items with examples
  • Size
  • Source code size: 16.53 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 221.73 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • satyakwok/reliakit
    6 2 17
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • satyakwok

reliakit-bulkhead

Crates.io Crates.io Downloads Docs.rs CI codecov License: MIT

A concurrency limiter for Rust.

reliakit-bulkhead caps how many operations may be in flight at once. It is a counting semaphore: acquire a permit before starting work, release it when the work finishes. When no permit is available the request is rejected immediately, so load is shed instead of piling up on a struggling dependency.

It does not block, sleep, spawn tasks, or read the clock — acquiring a permit either succeeds now or fails now. That keeps it usable from synchronous code, any async runtime, and no_std / embedded targets, with deterministic tests.

The crate has no dependencies, is #![no_std], and forbids unsafe code.

What This Crate Does

  • Bulkhead — a small Copy value: a fixed capacity and the number of permits currently held.
  • try_acquire(n) / try_acquire_one() — reserve permits when room exists and report whether it succeeded; an over-capacity request always fails and no partial acquire ever happens.
  • release(n) / release_one() — return permits; saturates at zero, so a stray release cannot underflow or panic.
  • available() / in_flight() / is_full() / is_empty() / reset() — inspect and clear the limiter.

What This Crate Does Not Do

It does not block to wait for a permit, queue requests, run work, or read time. There is no RAII guard: you pair acquire and release yourself (the type stays Copy and no_std as a result). Where reliakit-ratelimit caps the rate of operations over time, a bulkhead caps the number running at once; the two compose.

Installation

[dependencies]
reliakit-bulkhead = "0.1"

This crate is no_std and has no feature flags; it depends only on core.

Example

use reliakit_bulkhead::Bulkhead;

// Allow at most two concurrent operations.
let mut bulkhead = Bulkhead::new(2);

assert!(bulkhead.try_acquire_one()); // 1 in flight
assert!(bulkhead.try_acquire_one()); // 2 in flight
assert!(!bulkhead.try_acquire_one()); // full: rejected, shed load

bulkhead.release_one(); // one operation finished
assert!(bulkhead.try_acquire_one()); // room again

Releasing permits

Every successful acquire must be matched by a release, including on the error path, or the bulkhead slowly fills and rejects everything. The crate keeps the model explicit (no hidden guard) so it stays Copy and no_std; pair acquire/release yourself, e.g. with a manual Drop wrapper in your own code.

Feature Flags

This crate has no feature flags.

no_std

reliakit-bulkhead is #![no_std] and allocation-free — it depends only on core, with no third-party crates. Permit arithmetic saturates and the capacity is clamped to at least 1, so no input overflows, panics, or underflows.

Safety

This crate is #![forbid(unsafe_code)] and #![no_std].

Minimum Supported Rust Version

Rust 1.85 and newer. No nightly features are used.

Status

Pre-1.0. The API is small and stable; it may receive backward-compatible refinements before a 1.0 release.

License

Licensed under the MIT License. See LICENSE.