minipool 0.1.2

Lightweight, generic tokio-based pool implementation for Rust.
Documentation
  • Coverage
  • 100%
    9 out of 9 items documented1 out of 9 items with examples
  • Size
  • Source code size: 26.35 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.73 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • MarcelCoding

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

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.