blob: 25b79ff944f7bbecf13146257c7d000859d7c002 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
use std::ops::{Deref, DerefMut};
use tokio::io::{AsyncRead, AsyncWrite};
use super::{JabberReader, JabberStream, JabberWriter};
pub struct BoundJabberStream<S>(JabberStream<S>);
impl<S> Deref for BoundJabberStream<S>
where
S: AsyncWrite + AsyncRead + Unpin + Send,
{
type Target = JabberStream<S>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<S> DerefMut for BoundJabberStream<S>
where
S: AsyncWrite + AsyncRead + Unpin + Send,
{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<S> BoundJabberStream<S> {
pub fn split(self) -> (BoundJabberReader<S>, BoundJabberWriter<S>) {
let (reader, writer) = self.0.split();
(BoundJabberReader(reader), BoundJabberWriter(writer))
}
}
pub struct BoundJabberReader<S>(JabberReader<S>);
impl<S> BoundJabberReader<S> {
pub fn unsplit(self, writer: BoundJabberWriter<S>) -> BoundJabberStream<S> {
BoundJabberStream(self.0.unsplit(writer.0))
}
}
impl<S> std::ops::Deref for BoundJabberReader<S> {
type Target = JabberReader<S>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<S> std::ops::DerefMut for BoundJabberReader<S> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
pub struct BoundJabberWriter<S>(JabberWriter<S>);
impl<S> BoundJabberWriter<S> {
pub fn unsplit(self, reader: BoundJabberReader<S>) -> BoundJabberStream<S> {
BoundJabberStream(self.0.unsplit(reader.0))
}
}
impl<S> std::ops::Deref for BoundJabberWriter<S> {
type Target = JabberWriter<S>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<S> std::ops::DerefMut for BoundJabberWriter<S> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<S> JabberStream<S>
where
S: AsyncWrite + AsyncRead + Unpin + Send,
{
pub fn to_bound_jabber(self) -> BoundJabberStream<S> {
BoundJabberStream(self)
}
}
|