Skip to main content

picoring/
lib.rs

1pub mod buffer;
2pub mod collections;
3pub mod ring;
4pub mod spsc;
5pub mod system;
6
7#[cfg(feature = "python")]
8pub mod python;
9
10pub use buffer::MirrorBuffer;
11pub use collections::{PicoByteStream, PicoList, PicoQueue};
12pub use ring::PicoRing;
13pub use spsc::{create_spsc, PicoConsumer, PicoProducer, PicoSPSC};
14
15#[cfg(feature = "python")]
16#[pyo3::prelude::pymodule]
17fn picoring(m: &pyo3::prelude::Bound<'_, pyo3::prelude::PyModule>) -> pyo3::prelude::PyResult<()> {
18    python::init_module(m)
19}
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24
25    #[test]
26    fn it_works() {
27        let mut buf = MirrorBuffer::new(4096).unwrap();
28        let slice = buf.as_mut_slice();
29        slice[0] = 42;
30        assert_eq!(slice[4096], 42);
31    }
32
33    #[test]
34    fn test_alignment() {
35        let ps = system::get_page_size();
36        assert_eq!(buffer::align_to_page(0), 0);
37        assert_eq!(buffer::align_to_page(1), ps);
38        assert_eq!(buffer::align_to_page(ps - 1), ps);
39        assert_eq!(buffer::align_to_page(ps), ps);
40        assert_eq!(buffer::align_to_page(ps + 1), 2 * ps);
41        assert_eq!(buffer::align_to_page(2 * ps - 1), 2 * ps);
42    }
43}