ringbuf_blocking/wrap/
mod.rs

1mod cons;
2mod prod;
3
4use crate::rb::BlockingRbRef;
5use core::time::Duration;
6use ringbuf::{
7    traits::Based,
8    wrap::{caching::Caching, Wrap},
9    Obs,
10};
11
12pub struct BlockingWrap<R: BlockingRbRef, const P: bool, const C: bool> {
13    pub(crate) rb: R,
14    pub(crate) base: Caching<R, P, C>,
15    pub(crate) timeout: Option<Duration>,
16}
17
18impl<R: BlockingRbRef, const P: bool, const C: bool> BlockingWrap<R, P, C> {
19    pub fn new(rb: R) -> Self {
20        Self {
21            rb: rb.clone(),
22            base: Caching::new(rb),
23            timeout: None,
24        }
25    }
26
27    pub fn observe(&self) -> Obs<R> {
28        self.base().observe()
29    }
30}
31impl<R: BlockingRbRef, const P: bool, const C: bool> Based for BlockingWrap<R, P, C> {
32    type Base = Caching<R, P, C>;
33    fn base(&self) -> &Self::Base {
34        &self.base
35    }
36    fn base_mut(&mut self) -> &mut Self::Base {
37        &mut self.base
38    }
39}
40impl<R: BlockingRbRef, const P: bool, const C: bool> Wrap for BlockingWrap<R, P, C> {
41    type RbRef = R;
42    fn rb_ref(&self) -> &Self::RbRef {
43        &self.rb
44    }
45    fn into_rb_ref(self) -> Self::RbRef {
46        self.base.into_rb_ref()
47    }
48}
49
50impl<R: BlockingRbRef, const P: bool, const C: bool> AsRef<Self> for BlockingWrap<R, P, C> {
51    fn as_ref(&self) -> &Self {
52        self
53    }
54}
55impl<R: BlockingRbRef, const P: bool, const C: bool> AsMut<Self> for BlockingWrap<R, P, C> {
56    fn as_mut(&mut self) -> &mut Self {
57        self
58    }
59}
60
61#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
62pub enum WaitError {
63    TimedOut,
64    Closed,
65}
66
67pub use cons::*;
68pub use prod::*;