base_scheduler/
buffer_pool_options.rs1use std::io;
5
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub struct BufferPoolOptions {
9 pub buffers: usize,
10 pub buffer_size: usize,
11 pub alignment: usize,
13}
14
15impl BufferPoolOptions {
16 pub const fn new(buffers: usize, buffer_size: usize) -> Self {
17 Self {
18 buffers,
19 buffer_size,
20 alignment: 1,
21 }
22 }
23
24 pub(crate) fn validate(self) -> io::Result<()> {
25 if self.buffers == 0
26 || self.buffer_size == 0
27 || !self.alignment.is_power_of_two()
28 || self
29 .buffer_size
30 .checked_add(self.alignment - 1)
31 .and_then(|size| size.checked_mul(self.buffers))
32 .is_none_or(|size| size > isize::MAX as usize)
33 {
34 return Err(io::Error::new(
35 io::ErrorKind::InvalidInput,
36 "nonzero capacity and size, power-of-two alignment, and a representable allocation are required",
37 ));
38 }
39 Ok(())
40 }
41}