1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
//! A fast thread-safe bump allocation arena.
//!
//! `polymock` provides a fast allocation [`Arena`] using the bump allocation strategy. It's
//! primary use case is high-throughput multi-threaded network applications which allocate and free
//! buffers very frequently and cannot afford going through the global allocator.
//!
//! `polymock` only supports allocating `[u8]` buffers. It will never support allocating of
//! different objects.
//!
//! # Using `bytes`
//!
//! `polymock` provides it's own [`Bytes`](crate::Bytes) type that is a mostly drop-in replacement
//! for the equivalent type from the [`bytes`] crate.
//!
//! Once the construction using a custom vtable will be public, [`Bytes`](crate::Bytes) will be
//! deprecated in favor of the [`bytes`] crate.
//!
//! # `no_std` support
//!
//! `polymock` supports `no_std`, but requires the `alloc` crate. To enable `no_std` support
//! disable the default "std" feature:
//!
//! ```toml
//! polymock = { version = "0.2.0", default-features = false }
//! ```
//!
//! # Example
//!
//! ```
//! use polymock::Arena;
//!
//! let mut arena = Arena::default();
//!
//! let mut buf = arena.alloc(1500);
//!
//! for b in buf.iter_mut() {
//! *b = 1;
//! }
//!
//! let buf1 = buf.freeze();
//! let buf2 = buf1.clone();
//!
//! assert_eq!(buf1, buf2);
//! ```
//!
//! [`bytes`]: https://docs.rs/bytes/latest/bytes/index.html
#![no_std]
#![deny(unsafe_op_in_unsafe_fn)]
#![cfg_attr(docsrs, feature(doc_cfg))]
extern crate alloc;
#[cfg(any(feature = "std", test))]
extern crate std;
pub mod buf;
pub(crate) mod arena;
pub(crate) mod bytes;
pub(crate) mod bytes_mut;
pub(crate) mod loom;
pub use arena::Arena;
pub use buf::Buf;
pub use bytes::Bytes;
pub use bytes_mut::BytesMut;
#[inline(never)]
#[cold]
pub(crate) fn abort() -> ! {
#[cfg(feature = "std")]
{
std::process::abort();
}
#[cfg(not(feature = "std"))]
{
struct Abort;
impl Drop for Abort {
fn drop(&mut self) {
panic!();
}
}
panic!("abort");
}
}