diff --git a/crates/aligned-buffer-pool/src/buffer_pool.rs b/crates/aligned-buffer-pool/src/buffer_pool.rs index c43d723..a9206d0 100644 --- a/crates/aligned-buffer-pool/src/buffer_pool.rs +++ b/crates/aligned-buffer-pool/src/buffer_pool.rs @@ -11,7 +11,7 @@ use std::{ }; pub type UniquePooledAlignedBuffer< - P, + P = RetainAllRetentionPolicy, const ALIGNMENT: usize = DEFAULT_BUFFER_ALIGNMENT, A = Global, > = UniqueAlignedBuffer< @@ -20,7 +20,7 @@ pub type UniquePooledAlignedBuffer< >; pub type SharedPooledAlignedBuffer< - P, + P = RetainAllRetentionPolicy, const ALIGNMENT: usize = DEFAULT_BUFFER_ALIGNMENT, A = Global, > = SharedAlignedBuffer< @@ -231,28 +231,32 @@ impl< /// A pool for allocating and recycling aligned buffers. pub struct AlignedBufferPool< - P: BufferRetentionPolicy, - const ALIGNMENT: usize, + P: BufferRetentionPolicy = RetainAllRetentionPolicy, + const ALIGNMENT: usize = DEFAULT_BUFFER_ALIGNMENT, A: Allocator + Clone = Global, > { inner: Arc, A>>, } -impl AlignedBufferPool { - pub fn new(policy: P, capacity: usize) -> Self { - Self::new_in(policy, capacity, Global) - } -} - impl AlignedBufferPool where P: Default, { + pub fn new(capacity: usize) -> Self { + Self::with_policy(P::default(), capacity) + } + pub fn with_capacity(capacity: usize) -> Self { Self::with_capacity_in(capacity, Global) } } +impl AlignedBufferPool { + pub fn with_policy(policy: P, capacity: usize) -> Self { + Self::new_in(policy, capacity, Global) + } +} + impl AlignedBufferPool where @@ -292,8 +296,8 @@ impl } pub struct WeakAlignedBufferPool< - P: BufferRetentionPolicy, - const ALIGNMENT: usize, + P: BufferRetentionPolicy = RetainAllRetentionPolicy, + const ALIGNMENT: usize = DEFAULT_BUFFER_ALIGNMENT, A: Allocator + Clone = Global, > { inner: Weak, A>>, diff --git a/crates/aligned-buffer-pool/src/serializer_pool.rs b/crates/aligned-buffer-pool/src/serializer_pool.rs index b4b0b10..d34a640 100644 --- a/crates/aligned-buffer-pool/src/serializer_pool.rs +++ b/crates/aligned-buffer-pool/src/serializer_pool.rs @@ -1,6 +1,6 @@ use crate::{ buffer_pool::{AlignedBufferPoolInner, BufferPoolAllocator, WeakAlignedBufferPoolRef}, - BufferRetentionPolicy, + BufferRetentionPolicy, RetainAllRetentionPolicy, }; use aligned_buffer::{ alloc::{Allocator, Global}, @@ -18,11 +18,14 @@ use std::{ sync::{Arc, Weak}, }; -pub type SerializerAlignedBuffer = - SharedAlignedBuffer< - ALIGNMENT, - BufferPoolAllocator, A>, - >; +pub type SerializerAlignedBuffer< + P = RetainAllRetentionPolicy, + const ALIGNMENT: usize = DEFAULT_BUFFER_ALIGNMENT, + A = Global, +> = SharedAlignedBuffer< + ALIGNMENT, + BufferPoolAllocator, A>, +>; pub type SerializerPoolAllocator = BufferPoolAllocator, A>; @@ -68,7 +71,7 @@ where } pub struct SerializerPool< - P: BufferRetentionPolicy, + P: BufferRetentionPolicy = RetainAllRetentionPolicy, const ALIGNMENT: usize = DEFAULT_BUFFER_ALIGNMENT, A = Global, > where @@ -77,12 +80,35 @@ pub struct SerializerPool< inner: Arc>, } -impl SerializerPool { - pub fn new(policy: P, capacity: usize) -> Self { +impl SerializerPool +where + P: Default, +{ + pub fn new(capacity: usize) -> Self { + Self::with_policy(P::default(), capacity) + } + + pub fn with_capacity(capacity: usize) -> Self { + Self::with_capacity_in(capacity, Global) + } +} + +impl SerializerPool { + pub fn with_policy(policy: P, capacity: usize) -> Self { Self::new_in(policy, capacity, Global) } } +impl + SerializerPool +where + P: Default, +{ + pub fn with_capacity_in(capacity: usize, alloc: A) -> Self { + Self::new_in(P::default(), capacity, alloc) + } +} + impl SerializerPool where A: Allocator + Clone, @@ -136,17 +162,8 @@ where } } -impl SerializerPool -where - P: Default, -{ - pub fn with_capacity(capacity: usize) -> Self { - Self::new(P::default(), capacity) - } -} - pub struct Serializer< - P: BufferRetentionPolicy, + P: BufferRetentionPolicy = RetainAllRetentionPolicy, const ALIGNMENT: usize = DEFAULT_BUFFER_ALIGNMENT, A = Global, > where