1use std::{any::Any, any::TypeId, fmt, io, ops, task::Context, task::Poll};
2
3use crate::filter::{Filter, FilterReadStatus};
4use crate::{FilterCtx, Io, Readiness};
5
6pub struct Sealed(pub(crate) Box<dyn Filter>);
8
9impl fmt::Debug for Sealed {
10    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11        f.debug_struct("Sealed").finish()
12    }
13}
14
15impl Filter for Sealed {
16    #[inline]
17    fn query(&self, id: TypeId) -> Option<Box<dyn Any>> {
18        self.0.query(id)
19    }
20
21    #[inline]
22    fn process_read_buf(
23        &self,
24        ctx: FilterCtx<'_>,
25        nbytes: usize,
26    ) -> io::Result<FilterReadStatus> {
27        self.0.process_read_buf(ctx, nbytes)
28    }
29
30    #[inline]
31    fn process_write_buf(&self, ctx: FilterCtx<'_>) -> io::Result<()> {
32        self.0.process_write_buf(ctx)
33    }
34
35    #[inline]
36    fn shutdown(&self, ctx: FilterCtx<'_>) -> io::Result<Poll<()>> {
37        self.0.shutdown(ctx)
38    }
39
40    #[inline]
41    fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll<Readiness> {
42        self.0.poll_read_ready(cx)
43    }
44
45    #[inline]
46    fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll<Readiness> {
47        self.0.poll_write_ready(cx)
48    }
49}
50
51#[derive(Debug)]
52pub struct IoBoxed(Io<Sealed>);
54
55impl IoBoxed {
56    #[inline]
57    pub fn take(&mut self) -> Self {
61        IoBoxed(self.0.take())
62    }
63}
64
65impl<F: Filter> From<Io<F>> for IoBoxed {
66    fn from(io: Io<F>) -> Self {
67        Self(io.seal())
68    }
69}
70
71impl ops::Deref for IoBoxed {
72    type Target = Io<Sealed>;
73
74    #[inline]
75    fn deref(&self) -> &Self::Target {
76        &self.0
77    }
78}
79
80impl From<IoBoxed> for Io<Sealed> {
81    fn from(value: IoBoxed) -> Self {
82        value.0
83    }
84}