async_ringbuf/wrap/
mod.rs
1mod cons;
2mod prod;
3
4use crate::rb::AsyncRbRef;
5use ringbuf::{
6 traits::{observer::DelegateObserver, Based},
7 wrap::{direct::Direct, Wrap},
8 Obs,
9};
10
11pub struct AsyncWrap<R: AsyncRbRef, const P: bool, const C: bool> {
12 base: Option<Direct<R, P, C>>,
13}
14
15pub type AsyncProd<R> = AsyncWrap<R, true, false>;
16pub type AsyncCons<R> = AsyncWrap<R, false, true>;
17
18impl<R: AsyncRbRef, const P: bool, const C: bool> AsyncWrap<R, P, C> {
19 pub unsafe fn new(rb: R) -> Self {
20 Self {
21 base: Some(Direct::new(rb)),
22 }
23 }
24
25 pub fn observe(&self) -> Obs<R> {
26 self.base().observe()
27 }
28}
29
30impl<R: AsyncRbRef, const P: bool, const C: bool> Based for AsyncWrap<R, P, C> {
31 type Base = Direct<R, P, C>;
32 fn base(&self) -> &Self::Base {
33 self.base.as_ref().unwrap()
34 }
35 fn base_mut(&mut self) -> &mut Self::Base {
36 self.base.as_mut().unwrap()
37 }
38}
39
40impl<R: AsyncRbRef, const P: bool, const C: bool> Wrap for AsyncWrap<R, P, C> {
41 type RbRef = R;
42 fn rb_ref(&self) -> &R {
43 self.base().rb_ref()
44 }
45 fn into_rb_ref(self) -> R {
46 self.base.unwrap().into_rb_ref()
47 }
48}
49
50impl<R: AsyncRbRef, const P: bool, const C: bool> Unpin for AsyncWrap<R, P, C> {}
51
52impl<R: AsyncRbRef, const P: bool, const C: bool> DelegateObserver for AsyncWrap<R, P, C> {}
53
54impl<R: AsyncRbRef, const P: bool, const C: bool> AsRef<Self> for AsyncWrap<R, P, C> {
55 fn as_ref(&self) -> &Self {
56 self
57 }
58}
59impl<R: AsyncRbRef, const P: bool, const C: bool> AsMut<Self> for AsyncWrap<R, P, C> {
60 fn as_mut(&mut self) -> &mut Self {
61 self
62 }
63}