zbus/connection/socket/
split.rs1use 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 new(read: R, write: W) -> Self {
13 Self { read, write }
14 }
15
16 pub fn read(&self) -> &R {
18 &self.read
19 }
20
21 pub fn read_mut(&mut self) -> &mut R {
23 &mut self.read
24 }
25
26 pub fn write(&self) -> &W {
28 &self.write
29 }
30
31 pub fn write_mut(&mut self) -> &mut W {
33 &mut self.write
34 }
35
36 pub fn take(self) -> (R, W) {
38 (self.read, self.write)
39 }
40}
41
42pub type BoxedSplit = Split<Box<dyn ReadHalf>, Box<dyn WriteHalf>>;
44
45impl<S: Socket> From<S> for BoxedSplit {
46 fn from(socket: S) -> Self {
47 let split = socket.split();
48
49 Split {
50 read: Box::new(split.read),
51 write: Box::new(split.write),
52 }
53 }
54}