opus_codec/
alloc.rs

1/// Aligned storage for libopus state structures.
2#[derive(Debug)]
3pub struct AlignedBuffer {
4    buf: Vec<usize>,
5    bytes: usize,
6}
7
8impl AlignedBuffer {
9    /// Allocate at least `bytes` of pointer-aligned storage.
10    #[must_use]
11    pub fn with_capacity_bytes(bytes: usize) -> Self {
12        let word = std::mem::size_of::<usize>();
13        let len = bytes.div_ceil(word);
14        let buf = vec![0usize; len];
15        let bytes = len * word;
16        Self { buf, bytes }
17    }
18
19    /// Total available capacity in bytes.
20    #[must_use]
21    pub fn capacity_bytes(&self) -> usize {
22        self.bytes
23    }
24
25    /// Borrow the underlying buffer as a mutable pointer.
26    pub fn as_mut_ptr<T>(&mut self) -> *mut T {
27        self.buf.as_mut_ptr().cast()
28    }
29}