ranked_semaphore/
lib.rs

1//! # ranked-semaphore
2//!
3//! **A priority-aware semaphore for async Rust.**
4//!
5//! ## Features
6//! - Priority scheduling: Configurable priority-based task ordering
7//! - No runtime dependency: Works with any async runtime (Tokio, async-std, smol, etc.)
8//! - Flexible queue strategies: FIFO/LIFO and custom strategy
9//!
10//! ## Quick Start
11//! ```rust
12//! use ranked_semaphore::RankedSemaphore;
13//!
14//! #[tokio::main]
15//! async fn main() {
16//!     // Create a semaphore with 3 permits, FIFO strategy
17//!     let sem = RankedSemaphore::new_fifo(3);
18//!
19//!     // Acquire a permit (default priority)
20//!     let permit = sem.acquire().await.unwrap();
21//!
22//!     // Acquire with custom priority
23//!     let high = sem.acquire_with_priority(10).await.unwrap();
24//!
25//!     // Release permits automatically on drop
26//!     drop(permit);
27//!     drop(high);
28//! }
29//! ```
30//!
31//! ## Advanced Usage
32//!
33//! Use [`PriorityConfig`] and [`QueueStrategy`] for fine-grained control:
34//!
35//! ```rust
36//! use ranked_semaphore::{RankedSemaphore, PriorityConfig, QueueStrategy};
37//! use std::sync::Arc;
38//!
39//! let config = PriorityConfig::new()
40//!     .default_strategy(QueueStrategy::Fifo)
41//!     .exact(10, QueueStrategy::Lifo);
42//!
43//! let limiter = Arc::new(RankedSemaphore::new_with_config(2, config));
44//!
45//! let _admin = limiter.acquire_with_priority(10).await.unwrap();
46//! let _guest = limiter.acquire_with_priority(0).await.unwrap();
47//! ```
48//!
49//! See the [README](https://github.com/yeungkc/ranked-semaphore#readme) and [API docs](https://docs.rs/ranked-semaphore) for more details.
50#![cfg_attr(docsrs, feature(doc_cfg))]
51#![warn(missing_docs, unreachable_pub, missing_debug_implementations)]
52#![deny(rust_2018_idioms)]
53
54mod config;
55mod error;
56mod semaphore;
57mod wait_queue;
58
59pub use config::{PriorityConfig, QueueStrategy};
60pub use error::{AcquireError, TryAcquireError};
61pub use semaphore::{OwnedRankedSemaphorePermit, RankedSemaphore, RankedSemaphorePermit};
62
63pub use semaphore::{Acquire, AcquireOwned};