zbus/connection/socket/
split.rs
1use super::{ReadHalf, Socket, WriteHalf};
2
3#[derive(Debug)]
5pub struct Split<R: ReadHalf, W: WriteHalf> {
6 pub(super) read: R,
7 pub(super) write: W,
8}
9
10impl<R: ReadHalf, W: WriteHalf> Split<R, W> {
11 pub fn read(&self) -> &R {
13 &self.read
14 }
15
16 pub fn read_mut(&mut self) -> &mut R {
18 &mut self.read
19 }
20
21 pub fn write(&self) -> &W {
23 &self.write
24 }
25
26 pub fn write_mut(&mut self) -> &mut W {
28 &mut self.write
29 }
30
31 pub fn take(self) -> (R, W) {
33 (self.read, self.write)
34 }
35}
36
37pub type BoxedSplit = Split<Box<dyn ReadHalf>, Box<dyn WriteHalf>>;
39
40impl<S: Socket> From<S> for BoxedSplit {
41 fn from(socket: S) -> Self {
42 let split = socket.split();
43
44 Split {
45 read: Box::new(split.read),
46 write: Box::new(split.write),
47 }
48 }
49}