infinity_pool/builders/
blind_raw_builder.rs1use std::marker::PhantomData;
2
3use crate::{DropPolicy, RawBlindPool};
4
5#[derive(Debug, Default)]
7#[must_use]
8pub struct RawBlindPoolBuilder {
9 drop_policy: DropPolicy,
10
11 _not_send: PhantomData<*const ()>,
12}
13
14impl RawBlindPoolBuilder {
15 pub fn new() -> Self {
17 Self::default()
18 }
19
20 pub fn drop_policy(mut self, drop_policy: DropPolicy) -> Self {
22 self.drop_policy = drop_policy;
23 self
24 }
25
26 #[must_use]
28 pub fn build(self) -> RawBlindPool {
29 RawBlindPool::new_inner(self.drop_policy)
30 }
31}
32
33#[cfg(test)]
34#[cfg_attr(coverage_nightly, coverage(off))]
35mod tests {
36 use static_assertions::assert_not_impl_any;
37
38 use super::*;
39
40 assert_not_impl_any!(RawBlindPoolBuilder: Send, Sync);
41
42 #[test]
43 fn builder_creates_functional_pool() {
44 let pool = RawBlindPoolBuilder::new().build();
45
46 assert_eq!(pool.len(), 0);
47 assert!(pool.is_empty());
48 assert_eq!(pool.capacity_for::<u32>(), 0);
49 }
50
51 #[test]
52 fn builder_default_works() {
53 let pool = RawBlindPoolBuilder::default().build();
54
55 assert_eq!(pool.len(), 0);
56 assert!(pool.is_empty());
57 assert_eq!(pool.capacity_for::<String>(), 0);
58 }
59
60 #[test]
61 fn builder_with_may_drop_contents_policy() {
62 let mut pool = RawBlindPoolBuilder::new()
64 .drop_policy(DropPolicy::MayDropContents)
65 .build();
66
67 let _handle1 = pool.insert("test1".to_string());
69 let _handle2 = pool.insert(42_u32);
70
71 assert_eq!(pool.len(), 2);
72
73 drop(pool);
76 }
77
78 #[test]
79 #[should_panic]
80 fn builder_with_must_not_drop_contents_policy() {
81 let mut pool = RawBlindPoolBuilder::new()
83 .drop_policy(DropPolicy::MustNotDropContents)
84 .build();
85
86 let _handle = pool.insert(100_i64);
88 assert_eq!(pool.len(), 1);
89
90 drop(pool);
93 }
94}