pub struct Pool<T> { /* private fields */ }Expand description
A bounded pool where one thread acquires and any thread can return.
Only one Pool exists per pool. It cannot be cloned or shared
across threads (it is Send but not Sync or Clone).
When the Pool is dropped, outstanding Pooled guards
will drop their values directly instead of returning them to the pool.
§Example
use nexus_pool::sync::Pool;
let acquirer = Pool::new(
100,
|| Vec::<u8>::with_capacity(1024),
|v| v.clear(),
);
// Acquirer thread
let mut buf = acquirer.try_acquire().unwrap();
buf.extend_from_slice(b"hello");
// Can send buf to another thread
std::thread::spawn(move || {
println!("{:?}", &*buf);
// buf returns to pool on drop
}).join().unwrap();Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Pool<T>
impl<T> !RefUnwindSafe for Pool<T>
impl<T> Sync for Pool<T>
impl<T> Unpin for Pool<T>
impl<T> !UnwindSafe for Pool<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more