-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
Supplier is used to construct new instances, however the user may also want to control the maximum size allowed when items go back into the pool to avoid OOM.
I recommend the name Recycler, although you can use whatever name you think is fitting.
use case:
extern crate lifeguard;
use lifeguard::*;
fn main() {
let pool : Pool<String> = pool()
// The pool will allocate 128 values for immediate use. More will be allocated on demand.
.with(StartingSize(128))
// The pool will only grow up to 4096 values. Further values will be dropped.
.with(MaxSize(4096))
// The pool will use this closure (or other object implementing Supply<T>) to allocate
.with(Supplier(|| String::with_capacity(1024)))
// The pool will use this closure when adding recycled items back to the pool
.with(Recycler(|s| {
s.clear()
// nightly only
if s.capacity() > 4096 {
s.shrink_to(4096);
}
})
.build();
// ...
}
Metadata
Metadata
Assignees
Labels
No labels