2 releases
0.1.1 | Feb 2, 2025 |
---|---|
0.1.0 | Feb 2, 2025 |
#55 in #pool
280 downloads per month
10KB
146 lines
minipool
Lightweight, generic tokio-based pool implementation for Rust.
Usage
use std::ops::{Deref, DerefMut};
use minipool::{Pool, PoolEntry};
const BUF_SIZE: usize = 9000;
struct Buf(Box<[u8; BUF_SIZE]>);
impl PoolEntry for Buf {
fn is_closed(&self) -> bool {
false
}
}
// allows to call methods from `&[u8]` directly on `Buf`
impl Deref for Buf {
type Target = Box<[u8; BUF_SIZE]>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
// allows to call methods from `&mut [u8]` directly on `Buf`
impl DerefMut for Buf {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
async fn run() {
let pool = Pool::default();
pool.push(Buf(Box::new([0u8; BUF_SIZE])));
{
let buf = pool.acquire().await;
// do things with `buf`
}
// the buffer got reinserted into the pool
}
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies
~2–7.5MB
~47K SLoC