kitty_pool 0.1.1

A safe buffer pool
Documentation
kitty_pool-0.1.1 has been yanked.

crates-url codecov pipeline status

Kitty Pool

Ready For Production

The short answer is NO. This crate is not ready for production use. This is my first crate and frankly the crate will change after async makes it into stable.

A number of open tasks exist for the crate:

  • Is the API stable?
  • Is the crate performant enough?
  • Are there good examples?
  • Is there good documentation?
  • How does the crate interact with other useful libraries? I.E. can this crate effectively act as a single buffer for existing crates to avoid copies?

Purpose

The goal of this crate is to provide a safe and easy to use buffer pool in both a single-threaded and multi-threaded environment. The 'Kitty Pool' allows for requesting of 'Ranges', which act as owned slices into the buffer. The user of the 'Ranges' can then safely read and write to the owned parts of the buffer.

Example

use kitty_pool::*;

fn main() {
  let kitty_pool = KittyPool::new(
      1024 * 1024 * 100, // size of buffer to use
      4 * 1024 * 1024,   // size of fragments in buffer, must be divisible into the buffer
  );

  let rand_string: String = thread_rng()
          .sample_iter(&Alphanumeric)
          .take(REQUEST_SIZE)
          .collect();

  // Simple random data buffer
  let write_buffer = rand_string.into_bytes();

  // same size read buffer to fill
  let mut read_buffer = vec![0; REQUEST_SIZE];

  let result = pool
      .borrow_ranges(REQUEST_SIZE)
      .and_then(move |mut result| {
          let write_result = result.write(write_buffer.as_slice());
          assert!(write_result.is_ok());
          let read_result = result.read(read_buffer.as_mut_slice());
          assert!(read_result.is_ok());
          assert_eq!(write_result.unwrap(), read_result.unwrap());
          ok(())
      })
      .poll();

    assert!(result.is_ok());
    assert_eq!(write_buffer, read_buffer);
}

TODO

  • Filter pattern, should allow for using arbitrary segments of the owned ranges
  • Flag for contiguousness