use std::sync::Arc;
use easy_pool::{Clear, EasyPoolMutex, PoolMutex};
#[derive(EasyPoolMutex, Default)]
struct Test {
pets: Vec<String>,
}
impl Clear for Test {
fn clear(&mut self) {
self.pets.clear();
}
}
fn main() {
let mut test = Test::create_with(|| Test {
pets: Vec::with_capacity(100),
});
assert_eq!(test.pets.capacity(), 100);
test.pets.push("Cat".to_string());
assert_eq!(test.pets.first().unwrap(), "Cat");
test.pets.extend(vec!["Dog".to_string(); 100]);
assert_eq!(test.pets.len(), 101);
assert_eq!(test.pets.capacity(), 200);
drop(test);
let test = Test::create_with(|| Test {
pets: Vec::with_capacity(100),
});
assert_eq!(test.pets.len(), 0);
assert_eq!(test.pets.capacity(), 200);
let pool = Arc::new(PoolMutex::with_config(1024, 1024));
let result = pool.create_with(|| Test {
pets: Vec::with_capacity(100),
});
assert_eq!(result.pets.capacity(), 100);
}